In my code I want to "animate" a delay of drawing a line, so after adding a new line to the view, I call setNeedsDisplay - which works fine once.
Inside the drawRect method I draw the line and call a method of the line to increment the line-lengthl. Now I want to call setNeedsDisplay again to redraw the line - so it get's an animation of "growing"..
But it only calls setNeedsDisplay once & never again, except I add another line. I also tried to call a method in this class, which calls setNeedsDisplay, to make sure you can't call it inside of drawRect..
- (void)drawRect:(CGRect)rect {
for(GameLine *line in _lines) {
if(line.done) {
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(c, 5.0f);
CGContextSetStrokeColor(c, lineColor);
CGContextBeginPath(c);
CGContextMoveToPoint(c, line.startPos.x, line.startPos.y);
CGContextAddLineToPoint(c, line.endPos.x, line.endPos.y);
CGContextStrokePath(c);
}else {
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(c, 5.0f);
CGContextSetStrokeColor(c, delayColor);
CGContextBeginPath(c);
CGContextMoveToPoint(c, line.delayStartPos.x, line.delayStartPos.y);
CGContextAddLineToPoint(c, line.delayEndPos.x, line.delayEndPos.y);
CGContextStrokePath(c);
[line incrementDelayLine];
[self setNeedsDisplay];
}
}
}
_lines is a NSMutableArray with the GameLine objects (nonatomic, retain) property.