CALayerを回転させてみた。
UIViewを回転させるには、CGAffineTransformMakeRotationをsetTransform:すればいける。
ただ今回やりたかったのは、矩形の左下を基点に回転させること。
UIViewではanchorPointを設定できないことがわかったので、CALayerを使った。
anchorPointは、左上が(0.0)、右下が(1,1)となるので、左下は(0, 1)となる。
anchorPointを変更すると、設定したanchorPointの場所がpositionになる。
では、CALayerにanimationをさせる方法のさわりを紹介。
CALayerには、transformというプロパティがあるので、これをanimationしてやる。
そのために、transformをキーパスに指定したCABasicAnimationクラスを作ってやる。
transformのアニメーションの初期値と終了値を設定するが、この値はCATransform3D構造体である。
こいつをNSValueを使ってObjective-Cデータに変えてやる。CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"]; animation.fromValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(0 * M_PI / 180.0, 0.0, 0.0, 1.0)]; animation.toValue = ... [layer addAnimation:animation forKey:@"animation"];
こんな感じ。