美文网首页
CGContextSaveGState: invalid con

CGContextSaveGState: invalid con

作者: 啸狼天 | 来源:发表于2020-05-20 15:57 被阅读0次

用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方法.

相关文章

网友评论

      本文标题:CGContextSaveGState: invalid con

      本文链接:https://www.haomeiwen.com/subject/tsrnohtx.html