0

次のようにレイヤーをアニメーションで移動できます。

CABasicAnimation *animation = [CABasicAnimation animation];
[animation setFromValue:[NSValue valueWithCGPoint:self.layer.position]];
[animation setToValue:[NSValue valueWithCGPoint:CGPointMake(100, 100)]];
[self.layer addAnimation:animation forKey:@"position"];
self.layer.position = CGPointMake(100, 100);

ただし、アニメーションの終了後にlayer.positionを設定する必要があります。明示的なアニメーションを使用するときに自動的に設定する方法はありますか?

4

1 に答える 1

0

Apple のドキュメントによると、手動で設定する必要があります。

https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreAnimation_guide/CreatingBasicAnimations/CreatingBasicAnimations.html#//apple_ref/doc/uid/TP40004514-CH3-SW3

CABasicAnimation* fadeAnim = [CABasicAnimation animationWithKeyPath:@"opacity"];
fadeAnim.fromValue = [NSNumber numberWithFloat:1.0];
fadeAnim.toValue = [NSNumber numberWithFloat:0.0];
fadeAnim.duration = 1.0;
[theLayer addAnimation:fadeAnim forKey:@"opacity"];

// Change the actual data value in the layer to the final value.
theLayer.opacity = 0.0;

レイヤ オブジェクトのデータ値を更新する暗黙的なアニメーションとは異なり、明示的なアニメーションはレイヤ ツリーのデータを変更しません。明示的なアニメーションは、アニメーションを生成するだけです。アニメーションの最後に、Core Animation はレイヤーからアニメーション オブジェクトを削除し、現在のデータ値を使用してレイヤーを再描画します。明示的なアニメーションからの変更を永続的にしたい場合は、前の例に示すように、レイヤーのプロパティも更新する必要があります。

于 2013-03-04T16:33:29.660 に答える