旋转时如何中断/停止动画?

时间:2011-12-28 15:19:02

标签: ios animation core-animation rotation

例如,我在横向状态下使用动画,持续时间为5.0秒,从状态A到B;在5.0s的中间,我可以将iPad从横向旋转到纵向。我希望动画停止并在旋转后将UI状态设为C.

我不确定我的问题是否清楚。 我怎么能这样做?

我的动画代码:

- (void)moveImage:(UIImageView *)image duration:(NSTimeInterval)duration x:(NSNumber*)dx y:(NSNumber*)dy
{

    // Setup the animation
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:duration];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationBeginsFromCurrentState:YES];

    // The transform matrix
    float fx = [dx floatValue];
    float fy = [dy floatValue];

    CGAffineTransform transform = CGAffineTransformMakeTranslation(fx, fy);
    //CGAffineTransform transform = CGAffineTransformMakeRotation(0.4);
    //CGAffineTransform transform = CGAffineTransformMakeScale(2.0, 2.0);

    image.transform = transform;

    // Commit the changes
    [UIView commitAnimations];    
}

1 个答案:

答案 0 :(得分:2)

  1. Starting and Stopping Explicit Animations 有关于启动和停止核心动画的部分
  2. willRotateToInterfaceOrientation:duration 会在轮播开始时通知您。
  3. 所以我们要做的就是1)来自2)