如何停止UIViewAnimationOptionRepeat UIView动画? [英] How can I stop an UIViewAnimationOptionRepeat UIView Animation?

查看:1648
本文介绍了如何停止UIViewAnimationOptionRepeat UIView动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have the following code inside of a UIView subclass:

[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;
    }
}];

然后,当我想停止动画时,我将以下消息发送给View本身:

Then when I want to stop the Animation I send the following message to the View itself:

[[self layer] removeAllAnimations];

但它什么都不做......我怎么能停止动画?

But it does nothing... How can I stop the animation?

推荐答案

我使用以下代码修复:

- (void)restoreAnimations {

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

并在ViewController中调用它。

And calling it in the ViewController.

Btw。非常感谢Malloc!

Btw. Thanks a lot Malloc!

这篇关于如何停止UIViewAnimationOptionRepeat UIView动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆