【发布时间】:2012-02-27 23:02:44
【问题描述】:
从-drawRect: 获取 NSView 的 CGContext 并在以后执行更多绘图时是否安全?在这样一个简单的测试中:
CGContextRef context = NULL;
- (void)drawRect:(NSRect)r
{
if (!context)
context = [[NSGraphicsContext currentContext] graphicsPort];
}
- (void)drawSomething
{
CGContextSetRGBFillColor(context, 1, 0, 0, 1);
CGContextFillRect(context, CGRectMake (0, 0, 100, 100));
CGContextFlush(context);
}
调用-drawSomething 时似乎一切正常,但是否保证上下文不会改变?
正如您所见和猜到的,我试图绕过使用-drawRect: 的标准绘图方式。它适用于无数场合,但在我的特殊情况下,更程序化的绘图方式会让生活更轻松。
【问题讨论】:
标签: objective-c macos cocoa core-graphics quartz-2d