4

基本的に、次のようにポイントを中心にレイヤーを回転させています。

CATransform3D transform = CATransform3DIdentity;
transform.m34 = 1.0 / -500;
transform = CATransform3DTranslate(transform, rotationPoint.x-center.x, rotationPoint.y-center.y, 0.0);
transform = CATransform3DRotate(transform, (rotationAngleFor) * M_PI / 180.0f, 0.0, 1.0, 0);
transform = CATransform3DTranslate(transform, center.x-rotationPoint.x, center.y-rotationPoint.y, 0.0);

また、レイヤーを作成し、それをより大きなレイヤーに追加してから、変換を適用します。

[self.layer addSublayer:myLayer];
myLayer.transform = transform;

これをアニメートする方法は?

注 -これをUIViewアニメーション ブロックに配置しても機能しません。

4

1 に答える 1

9

編集: @DuncanC が指摘したように、私の説明は実際のコードと一致しませんでした。

CABasicAnimationレイヤーに追加された を次のように使用できます。

CABasicAnimation *transformAnimation = [CABasicAnimation animationWithKeyPath: @"transform"];

    <here goes your definition of transform>

transformAnimation.toValue = [NSValue valueWithCATransform3D:newTransform];
transformAnimation.duration = 10;
[self.layer addAnimation:transformAnimation forKey:@"transform"];

このアニメーションはtransform、レイヤーのプロパティの元の値から変換transformまで、レイヤーのプロパティを連続的に変更します。newTransform変更には 10 秒かかります。

于 2012-09-07T20:53:40.210 に答える