私のコードでは、線の描画の遅延を「アニメーション化」したいので、ビューに新しい線を追加した後、setNeedsDisplay を呼び出します。これは 1 回で問題なく動作します。
drawRect メソッド内で線を描画し、線のメソッドを呼び出して線の長さをインクリメントします。今度は setNeedsDisplay をもう一度呼び出して線を再描画したいので、「成長」のアニメーションを取得します..
しかし、別の行を追加しない限り、setNeedsDisplay は 1 回だけ呼び出され、二度と呼び出されません。また、setNeedsDisplay を呼び出すこのクラスのメソッドを呼び出して、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は、GameLine オブジェクト (非アトミック、保持) プロパティを持つ NSMutableArray です。