アップデート:
最近、180 度を超える回転、つまり連続回転を処理する別の方法を知りました。
CAValueFunction と呼ばれる特別なオブジェクトがあり、複数の完全な回転を指定する値を含む、任意の値を使用してレイヤーの変換に変更を適用できます。
レイヤーの変換プロパティの CABasicAnimation を作成しますが、変換を提供する代わりに、指定する値は新しい回転角度を与える NSNumber です。20pi のような新しい角度を指定すると、レイヤーは完全に 10 回転します (2pi/回転)。コードは次のようになります。
//Create a CABasicAnimation object to manage our rotation.
CABasicAnimation *rotation = [CABasicAnimation animationWithKeyPath:@"transform"];
rotation.duration = 10.0;
CGFLOAT angle = 20*M_PI;
//Set the ending value of the rotation to the new angle.
rotation.toValue = @(angle);
//Have the rotation use linear timing.
rotation.timingFunction =
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
/*
This is the magic bit. We add a CAValueFunction that tells the CAAnimation we are
modifying the transform's rotation around the Z axis.
Without this, we would supply a transform as the fromValue and toValue, and
for rotations > a half-turn, we could not control the rotation direction.
By using a value function, we can specify arbitrary rotation amounts and
directions and even rotations greater than 360 degrees.
*/
rotation.valueFunction =
[CAValueFunction functionWithName: kCAValueFunctionRotateZ];
/*
Set the layer's transform to it's final state before submitting the animation, so
it is in it's final state once the animation completes.
*/
imageViewToAnimate.layer.transform =
CATransform3DRotate(imageViewToAnimate.layer.transform, angle, 0, 0, 1.0);
[imageViewToAnimate.layer addAnimation:rotation forKey:@"transform.rotation.z"];
(実際のサンプル アプリケーションから上記のコードを抽出し、主題に直接関係のないものをいくつか取り出しました。このコードは、githubのプロジェクトKeyframeViewAnimations (リンク) で使用されていることがわかります。回転を行うコード「handleRotate」と呼ばれるメソッドにあります