1

次のサンプル コードを使用して (連続回転) を回転させていUIImageViewます。

CAKeyframeAnimation *theAnimation = [CAKeyframeAnimation animation];
theAnimation.values = [NSArray arrayWithObjects:
    [NSValue valueWithCATransform3D:CATransform3DMakeRotation(0, 0,0,1)],
    [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0,0,1)],
    [NSValue valueWithCATransform3D:CATransform3DMakeRotation(2*M_PI, 0,0,1)],
    nil];
theAnimation.cumulative = YES;
theAnimation.duration = duration;
theAnimation.repeatCount = HUGE_VALF;
theAnimation.removedOnCompletion = YES;
[self.layer addAnimation:theAnimation forKey:@"transform"];

アニメーションが表示されている間に、回転の速度を変更したい(異なる期間を意味する)。最も簡単な方法は、アニメーションを停止して新しいアニメーションを作成することです。これを行う際の問題は、新しいアニメーションが 0 度から開始され、回転するビューの速度が変化したときに見苦しいジャンプが発生することです。

アニメーションを中断せずにアニメーションの長さを変更するにはどうすればよいですか?

4

1 に答える 1

1

前の回転への参照を保存し、それを新しいアニメーションを作成するときの開始値として使用します。

CALayer* layer = [self.layer presentationLayer]; 
float currentAngle = [[layer valueForKeyPath:@"transform.rotation.z"] floatValue];

[self.layervalueForKeyPath.......ではなく[[self.layerpresentationLayer]valueForKeyPath .....を呼び出す必要がある理由についてもう少し詳しく説明しているのは、CoreAnimationプログラミングガイドで詳しく説明されています。 。回転(変換)はすでにアニメーション化されているため、提示されたレイヤーの値を確認する必要があります。

https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreAnimation_guide/Articles/CoreAnimationArchitecture.html

于 2012-12-10T17:17:33.257 に答える