用CAShapeLayer 绘制 不规则 『View 』时,报错信息如下:
CGContextSaveGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
代码
- (void)returnTopLayer:(UIView *)view cornerRadius:(CGSize)cornerRadius{
// UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect: view.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:cornerRadius];
UIBezierPath *maskPath = [UIBezierPath bezierPath];
[maskPath moveToPoint:CGPointMake(0, 0)];
[maskPath addLineToPoint:CGPointMake(view.width, 0)];
[maskPath addLineToPoint:CGPointMake(view.width, view.height)];
// [maskPath addArcWithCenter:CGPointMake(view.width/2.0, view.height) radius:view.width/2.0 startAngle:0 endAngle:M_PI clockwise:NO];
[maskPath addLineToPoint:CGPointMake(view.width/2.0, view.height/4.0*3)];
[maskPath addLineToPoint:CGPointMake(0, view.height)];
[maskPath addLineToPoint:CGPointMake(0, 0)];
[maskPath closePath];
// [maskPath stroke];
//创建 layer
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = view.bounds;
//赋值
maskLayer.path = maskPath.CGPath;
view.layer.mask = maskLayer;
}
image.png
原因:调用了- (void)stroke方法.
网友评论