【问题标题】:how can I interrupt/stop animation when I rotate?旋转时如何中断/停止动画?
【发布时间】:2012-01-29 06:28:24
【问题描述】:

比如我用横屏状态的动画,持续时间是5.0s,从状态A到B;在 5.0 年代中期,我可能会将 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];    
}

【问题讨论】:

  • 我编辑了您的问题以删除标签和单词 Xcode,因为您的问题与 Xcode 无关,而与 iOS 无关。您能否再次编辑您自己的问题以添加一些代码来向我们展示您是如何制作动画的?有几种方法可以制作动画,因此任何有用的答案都取决于您的实现。谢谢!

标签: ios animation core-animation rotation


【解决方案1】:
  1. Starting and Stopping Explicit Animations 有一个关于启动和停止核心动画的部分
  2. willRotateToInterfaceOrientation:duration 会在轮换开始时通知您。

所以所有要做的就是 1) 从 2)

【讨论】:

  • 谢谢。但我还是不明白。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-27
  • 2013-02-07
  • 1970-01-01
  • 2016-10-27
  • 2012-11-04
相关资源
最近更新 更多