I am wanting to build a small line graph that get updated when I call my setPointInGraph:
method. Each time I call that, I want the graph to be updated with the point that I just added, and therefore draw a line from my last point. I see the problem in my code below, in drawRect: that it just keeps overwriting the old path.
- (void)setPointInGraph:(float)p {
self.point = p;
[self setNeedsDisplay];
}
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGFloat maxX = CGRectGetMaxX(rect);
CGFloat maxY = CGRectGetMaxY(rect);
CGColorRef strokeColor = [self.lineColor CGColor];
CGContextSetStrokeColorWithColor(context, strokeColor);
CGContextSetLineWidth(context, self.lineWidth);
CGContextBeginPath(context);
CGContextMoveToPoint(context, 0.0, maxY - maxY * self.point);
CGContextAddLineToPoint(context, maxX * (point / count), maxY - maxY * self.point);
CGContextStrokePath(context);
count++;
}
在我选择的时候,我怎么能够绕过道路(例如财产)并更新道路? 我怎么能继续补充这条道路,不要超越它?