我取了一个数组:array,数组中的元素是通过一个定时器,每10秒添加一个,并调用 setneedsdisplay。
然后我的drawRect是这样写的:
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 2.0);
CGContextSetRGBStrokeColor(context, 0.231, 0.656, 0.849, 1.0);
CGContextBeginPath(context);
for (int i= 0; i< list.count; i++) {
firstPoint = CGPointMake(40 + [[list objectAtIndex:i] floatValue], 130);
lastPoint = CGPointMake(40 + [[list objectAtIndex:i] floatValue], 130-self.journey);
CGContextMoveToPoint(context, firstPoint.x, firstPoint.y);
CGContextAddLineToPoint(context, lastPoint.x, lastPoint.y);
}
CGContextStrokePath(context);
}
为什么每次只是绘制了一条线!?而不是连成一个整体的线条?!!!