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];

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

你可能感兴趣的:(iOS 开发之使用UIBezierPath报错)