UIGraphicsGetCurrentContext()

    技术2022-05-20  39

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

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

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

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

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

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

    终于,恍然大悟


    最新回复(0)