CABasicAnimation返回到下一个动画之前的原始位置

时间:2012-09-20 10:50:33

标签: ios rotation cabasicanimation

我想实现一种基于用户输入旋转UIButton的方法。在第一次输入时,它应向左旋转45度。在第二次输入时,它应该从第一次旋转后停止的位置旋转另外45度。

但是在开始第二个动画之前,按钮会回到原来的位置。以下是我使用的方法。

- (void)spinLayer:(CALayer *)inLayer duration:(CFTimeInterval)inDuration
        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 * 1/2 * direction];

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

    rotationAnimation.removedOnCompletion = NO;
    rotationAnimation.fillMode = kCAFillModeForwards;

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

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


}

0 个答案:

没有答案