當(dāng)使用了UIBezierPath有關(guān)的代碼的時候報(bào)錯,報(bào)錯如下:
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的相關(guān)源碼如下:
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];
查閱了網(wǎng)上的很多博客啥的者娱,最后發(fā)現(xiàn)是多了下面這句代碼:
[path fill];
去掉這句代碼就沒問題了...