CGContextStrokePath triggers EXC_BAD_ACCESS in iOS > 5 [duplicate]

别说谁变了你拦得住时间么 提交于 2019-12-05 16:26:51

The crash happens because the UIColors are already deallocated when you access the CGColorRefs.

An easy way to avoid this is to use

UIColor* blackColor = [UIColor blackColor];
CGContextSetStrokeColorWithColor(context, [blackColor CGColor]);

instead of

CGColorRef* blackColor = [[UIColor blackColor] CGColor];
CGContextSetStrokeColorWithColor(context, blackColor);

so ARC doesn't get the chance to deallocate the UIColor objects early.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!