为什么第二个圆圈没有显示?
Why this 2nd circle didn't show?
如果我注释了 shapeShadow 代码,它将显示第二个圆圈。
-(void)shapeShadow:(UIBezierPath *)shape
发生了什么?
-(void)shapeShadow:(UIBezierPath *)shape 这段代码是在圆圈中添加线条。
#import "SetCard.h"
@implementation SetCard
-(void)drawRect:(CGRect)rect
{
UIBezierPath *roundedRect=[UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:10];
[roundedRect addClip];
[[UIColor whiteColor]setFill];
UIRectFill(self.bounds);
[[UIColor blackColor]setStroke];
[self drawShape];
}
-(void)drawShape
{
CGContextRef context=UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
for (int i=1; i<3; i++) {
CGContextTranslateCTM(context, self.bounds.size.width*(i-1)/3, 0);
[self drawCircle];
}
CGContextRestoreGState(context);
}
-(UIBezierPath *)drawCircle
{
CGPoint center=CGPointMake(self.bounds.size.height/5, self.bounds.size.height/2);
UIBezierPath *circle=[UIBezierPath bezierPathWithArcCenter:center radius:self.bounds.size.height/5 startAngle:0 endAngle:12 clockwise:YES];
[circle closePath];
circle.lineWidth=3;
[[UIColor blueColor]setFill];
[[UIColor blackColor]setStroke];
[circle stroke]; [self shapeShadow:circle];
return circle;
}
-(void)shapeShadow:(UIBezierPath *)shape
{
// [shape addClip];
// for(int j=0;j<15;j++){
// CGFloat c=0.05*j*self.bounds.size.height;
// UIBezierPath *line=[UIBezierPath bezierPath];
// [line moveToPoint:CGPointMake(c, 0.0)];
// [line addLineToPoint:CGPointMake(c, self.bounds.size.height)];
// line.lineWidth=2;
// [line fill];[line stroke];
// }
}
@end
因为该方法调用 [shape addClip]
并将路径转换为裁剪规范,因此它不再绘制,所以它阻止在指定区域绘制。
如果我注释了 shapeShadow 代码,它将显示第二个圆圈。
-(void)shapeShadow:(UIBezierPath *)shape
发生了什么?
-(void)shapeShadow:(UIBezierPath *)shape 这段代码是在圆圈中添加线条。
#import "SetCard.h"
@implementation SetCard
-(void)drawRect:(CGRect)rect
{
UIBezierPath *roundedRect=[UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:10];
[roundedRect addClip];
[[UIColor whiteColor]setFill];
UIRectFill(self.bounds);
[[UIColor blackColor]setStroke];
[self drawShape];
}
-(void)drawShape
{
CGContextRef context=UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
for (int i=1; i<3; i++) {
CGContextTranslateCTM(context, self.bounds.size.width*(i-1)/3, 0);
[self drawCircle];
}
CGContextRestoreGState(context);
}
-(UIBezierPath *)drawCircle
{
CGPoint center=CGPointMake(self.bounds.size.height/5, self.bounds.size.height/2);
UIBezierPath *circle=[UIBezierPath bezierPathWithArcCenter:center radius:self.bounds.size.height/5 startAngle:0 endAngle:12 clockwise:YES];
[circle closePath];
circle.lineWidth=3;
[[UIColor blueColor]setFill];
[[UIColor blackColor]setStroke];
[circle stroke]; [self shapeShadow:circle];
return circle;
}
-(void)shapeShadow:(UIBezierPath *)shape
{
// [shape addClip];
// for(int j=0;j<15;j++){
// CGFloat c=0.05*j*self.bounds.size.height;
// UIBezierPath *line=[UIBezierPath bezierPath];
// [line moveToPoint:CGPointMake(c, 0.0)];
// [line addLineToPoint:CGPointMake(c, self.bounds.size.height)];
// line.lineWidth=2;
// [line fill];[line stroke];
// }
}
@end
因为该方法调用 [shape addClip]
并将路径转换为裁剪规范,因此它不再绘制,所以它阻止在指定区域绘制。