【发布时间】:2010-04-03 19:58:39
【问题描述】:
这是我用来绘制的代码:
- (void) drawSomething
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBStrokeColor(context, 1, 0, 0, 1);
CGContextSetLineWidth(context, 6.0);
CGContextMoveToPoint(context, 100.0f, 100.0f);
CGContextAddLineToPoint(context, 200.0f, 200.0f);
CGContextStrokePath(context);
NSLog(@"draw");
}
但是我得到了这样的错误:
[Session started at 2010-04-03 17:51:07 +0800.]
Sat Apr 3 17:51:09 MacBook.local MyApp[12869] <Error>: CGContextSetRGBStrokeColor: invalid context
Sat Apr 3 17:51:09 MacBook.local MyApp[12869] <Error>: CGContextSetLineWidth: invalid context
Sat Apr 3 17:51:09 MacBook.local MyApp[12869] <Error>: CGContextMoveToPoint: invalid context
Sat Apr 3 17:51:09 MacBook.local MyApp[12869] <Error>: CGContextAddLineToPoint: invalid context
Sat Apr 3 17:51:09 MacBook.local MyApp[12869] <Error>: CGContextDrawPath: invalid context
为什么提示我说上下文无效?
【问题讨论】:
-
你从什么地方调用 drawSomething?那么当前的上下文应该是什么?
-
它从我的 init 方法中调用。当前上下文不是当前视图?
标签: iphone objective-c xcode quartz-graphics