- (void)viewDidLoad { [super viewDidLoad]; CALayer *layer = [CALayer layer]; layer.position = CGPointMake(0, 0); layer.anchorPoint = CGPointMake(0, 0); layer.bounds = self.view.bounds; layer.backgroundColor = [UIColor grayColor].CGColor; [self.view.layer addSublayer:layer]; layer.delegate = self; [layer setNeedsDisplay]; } - (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx { [[UIBezierPath bezierPathWithRect:CGRectMake(200, 200, 200, 200)]stroke]; // CGContextAddRect(ctx, CGRectMake(200, 200, 200, 200)); // CGContextStrokePath(ctx); }
通过C语言方式可以绘制,但是使用UIBezierPath无法绘制,并报如下错误信息:
Mar 2 22:54:42 test[1485] <Error>: CGContextSaveGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable. Mar 2 22:54:42 test[1485] <Error>: CGContextSetLineWidth: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable. Mar 2 22:54:42 test[1485] <Error>: CGContextSetLineJoin: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable. Mar 2 22:54:42 test[1485] <Error>: CGContextSetLineCap: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable. Mar 2 22:54:42 test[1485] <Error>: CGContextSetMiterLimit: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable. Mar 2 22:54:42 test[1485] <Error>: CGContextSetFlatness: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable. Mar 2 22:54:42 test[1485] <Error>: CGContextAddPath: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable. Mar 2 22:54:42 test[1485] <Error>: CGContextDrawPath: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable. Mar 2 22:54:42 test[1485] <Error>: CGContextRestoreGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
请各位大神指教!!!
http://stackoverflow.com/questions/32236204/cgcontextsavegstate-invalid-context-0x0-error-only-on-device
还是不明白