Tat*_*tat 7 iphone xcode objective-c quartz-graphics
这是我用来绘制的代码:
- (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");
}
Run Code Online (Sandbox Code Playgroud)
但是我得到了这样的错误:
[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
Run Code Online (Sandbox Code Playgroud)
为什么它促使我说上下文无效?
Tho*_*lin 12
就像文档说的那样:
默认情况下,当前图形上下文为零.在调用drawRect:方法之前,视图对象将有效的上下文推送到堆栈,使其成为当前的.
所以你需要把这段代码放在drawRect方法中
| 归档时间: |
|
| 查看次数: |
13869 次 |
| 最近记录: |