【问题标题】:How can I stop an UIViewAnimationOptionRepeat UIView Animation?如何停止 UIViewAnimationOptionRepeat UIView 动画?
【发布时间】:2013-12-08 15:49:44
【问题描述】:

我在 UIView 子类中有以下代码:

[element setAlpha: 0.0f];

[UIView animateWithDuration: 0.4 delay: 0.0 options: UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat animations: ^{
    [element setAlpha: 1.0f];
} completion: ^(BOOL finished){
    if (finished) 
    {
        return;
    }
}];

然后,当我想停止动画时,我会向视图本身发送以下消息:

[[self layer] removeAllAnimations];

但它什么也没做...我怎样才能停止动画?

【问题讨论】:

  • 别忘了:#import <QuartzCore/QuartzCore.h>
  • 试试:[self.layer removeAllAnimations];,还有,你有没有编译警告?
  • 不,可能是我调用[self.layer removeAllAnimations]的地方。我应该在视图内部还是在包含视图的 ViewController 中调用它?
  • 你不应该在element.layer 上打电话给removeAllAnimations,而不是self.layer吗?

标签: ios iphone uiview ios7 uiviewanimation


【解决方案1】:

我使用以下代码进行了修复:

- (void)restoreAnimations {

    [UIView animateWithDuration:0.1 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveLinear animations:^{
        [element setAlpha: 1.0f];
    } completion:NULL];
}

并在 ViewController 中调用它。

顺便说一句。非常感谢 Malloc!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    • 2013-10-25
    • 2019-09-23
    相关资源
    最近更新 更多