CoreAnimation でシェイプをアニメーション化するのと同様の問題に直面しています
私には習慣がありますUIView
MyUIView
- (void)drawRect:(CGRect)rect {
// Right here, I might also draw some triangle, circle which I do not wish
// to be animated.
// ...
// Calculate minX, minY, ... based on rect and self->value.
// ...
// Draw a rounded rectangle based on minX, minY, ...
// The x-location of rounded rectangle will be different for difference self->value
CGContextMoveToPoint(context, minx, midy);
CGContextAddArcToPoint(context, maxx, maxy, midx, maxy, radius);
...
...
CGContextDrawPath(context, kCGPathFillStroke);
}
// Usually trigger by controller via button clicked
- (void) setValueViaButtonClicked:(double) value {
self->currentValue = value;
dispatch_async(dispatch_get_main_queue(), ^{
[self setNeedsDisplay];
});
}
現在、古い値とは異なる新しい値でボタンをクリックするたびに、角丸四角形が古い位置から新しい位置に移動するのを確認できますが、アニメーションは表示されません。
明示的なボタンクリック時のみ、アニメーションを作成したいと思います。私が見たほとんどの例では、アニメーション コードはコントローラー内で実行されます。
- アニメーションは Layer と CGPathCreateMutable を介して行われます
- Layer と CGPathCreateMutable の作成は、View Controller で実行されます。
MyUIView
を介して上記のタスクを実行するにはどうすればよいsetValueViaButtonClicked
でしょうか? drawRect からの適切なrect
情報がないため、から作成されたパスの情報をどのように構成するのCGPathCreateMutable
でしょうか?