现在的位置: 首页 > 综合 > 正文

UIGraphicsGetCurrentContext 理解

2013年09月09日 ⁄ 综合 ⁄ 共 305字 ⁄ 字号 评论关闭

想在initWithFrame或者其他函数里调用UIGraphicsGetCurrentContext()函数,

结果被告知Invalid Context,查资料。

按照文档中的说法,系统会维护一个CGContextRef的栈,而UIGraphicsGetCurrentContext()会取栈顶的CGContextRef,

正确的做法是只在drawRect里调用UIGraphicsGetCurrentContext(),

因为在drawRect之前,系统会往栈里面压入一个valid的CGContextRef,

除非自己去维护一个CGContextRef,否则不应该在其他地方取CGContextRef。

终于,恍然大悟

抱歉!评论已关闭.