iOS 开发之使用UIBezierPath报错

当使用了UIBezierPath有关的代码的时候报错,报错如下:

2018-08-13 16:15:44.250488+0800 KODJunkResourceCreater[11739:2817028] [Unknown process name] CGContextSetFlatness: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2018-08-13 16:15:44.250628+0800 KODJunkResourceCreater[11739:2817028] [Unknown process name] CGContextAddPath: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2018-08-13 16:15:44.250864+0800 KODJunkResourceCreater[11739:2817028] [Unknown process name] CGContextDrawPath: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2018-08-13 16:15:44.251521+0800 KODJunkResourceCreater[11739:2817028] [Unknown process name] CGContextRestoreGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2018-08-13 16:15:44.253088+0800 KODJunkResourceCreater[11739:2817028] [Unknown process name] CGContextSaveGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2018-08-13 16:15:44.260626+0800 KODJunkResourceCreater[11739:2817028] [Unknown process name] CGContextSetFlatness: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2018-08-13 16:15:44.262021+0800 KODJunkResourceCreater[11739:2817028] [Unknown process name] CGContextAddPath: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2018-08-13 16:15:44.262296+0800 KODJunkResourceCreater[11739:2817028] [Unknown process name] CGContextDrawPath: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2018-08-13 16:15:44.262616+0800 KODJunkResourceCreater[11739:2817028] [Unknown process name] CGContextRestoreGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2018-08-13 16:15:44.263503+0800 KODJunkResourceCreater[11739:2817028] [Unknown process name] CGContextSaveGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2018-08-13 16:15:44.263632+0800 KODJunkResourceCreater[11739:2817028] [Unknown process name] CGContextSetFlatness: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2018-08-13 16:15:44.267706+0800 KODJunkResourceCreater[11739:2817028] [Unknown process name] CGContextAddPath: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2018-08-13 16:15:44.268018+0800 KODJunkResourceCreater[11739:2817028] [Unknown process name] CGContextDrawPath: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2018-08-13 16:15:44.268524+0800 KODJunkResourceCreater[11739:2817028] [Unknown process name] CGContextRestoreGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2018-08-13 16:15:44.268777+0800 KODJunkResourceCreater[11739:2817028] [Unknown process name] CGContextSaveGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE envir

UIBezierPath的相关源码如下:

    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(point1X, point1Y)];
    [path addLineToPoint:CGPointMake(point2X, point2Y)];
    [path addLineToPoint:CGPointMake(point3X, point3Y)];
    [path addLineToPoint:CGPointMake(point4X, point4Y)];
    [path closePath];
    [path fill];
    
    CAShapeLayer *shapeLayer = [[CAShapeLayer alloc] init];
    shapeLayer.path = path.CGPath;
    shapeLayer.fillColor = randomColor.CGColor;
    shapeLayer.lineCap = kCALineCapRound;
    shapeLayer.lineJoin = kCALineJoinRound;
    shapeLayer.strokeColor = [UIColor clearColor].CGColor;
    shapeLayer.lineWidth = path.lineWidth;
    [self.layer addSublayer:shapeLayer];

查阅了网上的很多博客啥的,最后发现是多了下面这句代码:

[path fill];

去掉这句代码就没问题了...

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 175,627评论 25 709
  • 因为要结局swift3.0中引用snapKit的问题,看到一篇介绍Xcode8,swift3变化的文章,觉得很详细...
    uniapp阅读 10,057评论 0 12
  • 需求 由于需求的原因要做到视频的实时渲染但是并不改变原视频,也就是说不是针对视频本身去加滤镜,所以就一直在网上找方...
    朱亦鸣阅读 10,532评论 0 5
  • 在谈教育的时候,总有老师或家长把问题抛给制度和社会,认为是制度和社会在逼TA这样做,没有办法,只能先适应...
    杨林柯阅读 4,565评论 2 2
  • 1 一入职场深似海,从此下班是路人。 如果你身处北上广深,想必每天都会做一个朝九晚五的梦。 梦很美好,可惜是反的。...
    傅踢踢阅读 7,482评论 18 58