使用BOOL /完成块停止自动反转/无限重复UIView动画 [英] Stop an auto-reverse / infinite-repeat UIView animation with a BOOL / completion block

查看:341
本文介绍了使用BOOL /完成块停止自动反转/无限重复UIView动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设置以下 UIView animateWithDuration:方法,目的是在其他地方设置我的 animationOn BOOL在程序中取消无限循环重复。我的印象是每次动画循环结束时都会调用完成块,但似乎不是这样。

I'm setting up the following UIView animateWithDuration: method, with the intention of setting my animationOn BOOL elsewhere in the program to cancel that infinite looped repeat. I was under the impression that the completion block would be called each time a cycle of the animation ends, but this doesn't appear to be the case.

重复动画中是否曾调用完成块?如果没有,是否有另一种方法可以在此方法之外停止此动画?

Is the completion block ever called in a repeating animation? And if not, is there another way I can stop this animation from outside this method?

- (void) animateFirst: (UIButton *) button
{
    button.transform = CGAffineTransformMakeScale(1.1, 1.1);
    [UIView animateWithDuration: 0.4
                          delay: 0.0
                        options: UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat
                     animations: ^{
                         button.transform = CGAffineTransformIdentity;
                     } completion: ^(BOOL finished){
                         if (!animationOn) {
                             [UIView setAnimationRepeatCount: 0];
                         }
    }];
}


推荐答案

完成块只会获得动画中断时调用。例如,当应用程序进入后台并再次返回前台时(通过多任务处理),它会被调用。在这种情况下,动画停止。当发生这种情况时你应该重新启动动画。

The completion block will only get called when the animation is interrupted. For example it gets called when the app goes in the background and comes back to the foreground again (via multitasking). In that case the animation is stopped. You should restart the animation when that happens.

要停止动画,你可以从视图的层中删除它:

To stop the animation you can remove it from the view's layer:

[button.layer removeAllAnimations];

这篇关于使用BOOL /完成块停止自动反转/无限重复UIView动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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