今天碰到一个问题,自定义了一个CALayer,并且在layer的drayInContext绘制直线,但是绘制线的时候,log中打印出以下错误提示:
CGContextSetStrokeColorWithColor: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
只需要在drawInContext:(CGContextRef)ctx的最上方加上UIGraphicsPushContext(ctx)即可。

本文解决了自定义CALayer在drawInContext中绘制直线时出现的严重错误:CGContextSetStrokeColorWithColor:invalid context 0x0。通过在drawInContext方法开始处添加UIGraphicsPushContext(ctx),可以避免这一问题。
6762

被折叠的 条评论
为什么被折叠?



