首页 新闻 搜索 专区 学院

无法再drawLayer方法中使用UIBezierPath绘图,为什么?

0
悬赏园豆:200 [待解决问题]
- (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.

请各位大神指教!!!

Matrix_Neo的主页 Matrix_Neo | 初学一级 | 园豆:2
提问于:2016-03-02 22:57
< >
分享
所有回答(1)
0

http://stackoverflow.com/questions/32236204/cgcontextsavegstate-invalid-context-0x0-error-only-on-device

刘宏玺 | 园豆:14020 (专家六级) | 2016-03-03 10:27

还是不明白

支持(0) 反对(0) Matrix_Neo | 园豆:2 (初学一级) | 2016-03-05 21:54
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册