如何取消UIViews基于块的动画? [英] How to cancel UIViews block-based animation?

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

问题描述

我目前关注以下问题:

我启动动画,其中触发了2个对象属性。

i start an animation, where 2 objects-attributes are triggered.

代码是:

    [UIView animateWithDuration:0.3 animations:^{
        greyscaleImage.alpha     = 1;
        activityIndicator.alpha  = 1;
    } completion:^(BOOL f){
        if(f)
        {
            [activityIndicator startAnimating];
        }
    }];

工作正常。

唯一我发现的问题是,当我释放持有此activityIndi​​cator和greyscaleImage的视图时,我有0.3秒的更改来崩溃应用程序。

the only problem i discovered is, that i have a 0.3 seconds change to crash the app when the view which holds this activityIndicator and greyscaleImage is deallocated.

为了让它更清晰,请设想一个ViewController,它的视图通过默认的iOS模式-View方式呈现。现在触发该动画,需要2分钟。在达到2分钟之前,你会发现动画很无聊,你想要忽略那个视图。现在,发布了view,activityIndi​​cator和greyscaleImage,动画o / c不知道该怎么做。

To make it more clear please imagine a ViewController, its view presented via default iOS-modal-View ways. Now trigger that animation, which takes 2 minutes. before reaching that 2 minutes, you find that animation is quite boring and you want to dismiss that view. now, that the view, activityIndicator and greyscaleImage are released, the animation o/c cannot know what to do.

所以我想知道,这里做什么+调试器的原因指向

so i wonder, what to do here + why the debugger points to

  } completion:^(BOOL f){

而不是例如[activityIndi​​cator ...

instead of e.g. [activityIndicator ...

有没有办法允许用户在2分钟结束前解除视图?

is there a way, to allow user to dismiss the view before the 2 minutes are over?

最好的问候

推荐答案

如果你开始一个新的动画需要0.0秒进入你要去的状态,它将取消旧的并开始新的(即时)'动画'。

If you start a new animation that takes 0.0 seconds and goes to the state you want to go to, it will cancel the old one and start the new (instant) 'animation'.

你想要什么时候的例子通过前往它已经到达的位置停止移动视图:

Example for when you want to stop a moving view by going to the place it already is at:

[UIView animateWithDuration:0.0
                      delay:0.0
                    options:UIViewAnimationOptionBeginFromCurrentState
                 animations:^{movingView.frame = ((CALayer *)movingView.layer.presentationLayer).frame;}
                 completion:^(BOOL finished){}
 ];

选项:UIViewAnimationOptionBeginFromCurrentState很重要。不调用它会让你的动画从上一个动画的结束状态开始。在移动中,它会在变形到你希望它停在的地方之前变形到最终位置。即使你的取消 - '动画'是即时的,也可以看到来回跳跃。

options:UIViewAnimationOptionBeginFromCurrentState is important. Not calling it will let your animation start at the end state of the previous animation. In movement, it would warp to the end location before warping to the place you want it to stop at. Even though your cancel-'animation' is instant, the jumping back and forth may be visible.

注意:动画时间不一定是0.0秒,任何动画将取消旧的动画。但不完全确定不同类型的动画。例如,我不知道更改框架是否会阻止淡入淡出。

Note: The animation time doesn't have to be 0.0 seconds, any animation will cancel the old one. Not entirely sure about different types of animations though. For example, I don't know if changing a frame would stop a fade.

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

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