0

ランダムな角度で同時に回転、縮小、および画面外への移動を行うカスタム UIView クラスがあります。

レイヤーを数回スピンするこのコードがあります

- (void)spinLayer:(CALayer *)inLayer duration:(CFTimeInterval)inDuration currentAngle:(CGFloat)curAngle
        direction:(int)direction
{
    CABasicAnimation* rotationAnimation;

    // Rotate about the z axis
    rotationAnimation = 
    [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];

    // Rotate 360 degress, in direction specified
    rotationAnimation.toValue = [NSNumber numberWithFloat:(M_PI * 4 * direction) + curAngle];

    // Perform the rotation over this many seconds
    rotationAnimation.duration = inDuration;

    // Set the pacing of the animation
    rotationAnimation.timingFunction = 
    [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];

    // Add animation to the layer and make it so
    [inLayer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}

私はこれを次のように呼びます:

CGFloat angle = atan2(sender.transform.b, sender.transform.a);  // Current angle
[self spinLayer:sender.layer duration:0.5 currentAngle:angle direction:1]; //direction can be -1

しかし、ビューを縮小すると同時に移動するにはどうすればよいでしょうか?

ありがとう

4

1 に答える 1

1

ビューを360度回転すると、開始状態と終了状態が同じであるため、アニメーションは生成されません。回転値にはいくつかの値を使用してみてください。

于 2012-06-06T15:02:57.313 に答える