我正在研究斯坦福大学CS193p课程,并试图绘制图形。绘制轴的工作原理,但我无法绘制图形本身。我收到消息在drawRect()方法中绘制CoreGraphics行的麻烦
CGContextAddLineToPoint: no current point.
当我尝试绘制。这是代码。
- (void)drawRect:(CGRect)rect
{
NSLog(@"Drawing Graph View");
CGPoint origin = CGPointMake(20, 350);
CGRect rect2 = CGRectMake(origin.x, origin.y, 250, -250);
[AxesDrawer drawAxesInRect:rect2 originAtPoint:origin scale:[self scale]];
CGContextRef context = UIGraphicsGetCurrentContext();
UIGraphicsPushContext(context);
CGContextSetLineWidth(context, 2);
[[UIColor redColor] setStroke];
CGContextMoveToPoint(context, origin.x, origin.y);
for (CGFloat i=0; i<250; i++) {
CGFloat yChange = [self.dataSource deltaY:self];
CGContextAddLineToPoint(context, origin.x+i, origin.y-yChange);
CGContextStrokePath(context);
}
UIGraphicsPopContext();
}
谢谢你的工作完美。 – MaxGabriel 2012-02-05 16:25:41
多数民众赞成在我工作.. – 2013-11-27 10:32:36