停止重复的UIView动画块? [英] Stop Repeating UIView Animation Block?

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

问题描述

我的系统使用的UIView动画块的 UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoReverse 选项,它保持下去,但在某些点上我需要停止动画,但更重要的是停止并有视图退回到原来的位置。

I have a UIView animation block which uses the UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoReverse option so it keeps going, but at some points I need to stop the animation but more importantly stop it and have the view return to its original position.

我曾尝试 [dot1.layer removeAllAnimations]; 但它停止在其轨道上,不会将其返回到原来的位置,它停止中旬动画

I have tried [dot1.layer removeAllAnimations]; but that stops it in its tracks without returning it to its original position, it stops mid animation.

我曾尝试停止它,然后只是运行第二个动画将其放回正确的框架,但可以有点生涩,因为我不知道它需要走多远,什么时间等。

I have tried stopping it then just running a second animation to return it to its correct frame, but that can be a bit jerky as I don't know how far it needs to go with what duration etc.

那么,这可能只是有它完成了最后一个周期后,停止动画,而不是中期的方式?

So is it possible to simply have the animation stop after its completed its last cycle rather than mid way?

感谢。

推荐答案

您应该试试这个:

[UIView animateWithDuration:2 delay:0 options:UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction animations:^
{
    view.frame = CGRectMake(0, 100, 200, 200);
} completion:^(BOOL finished)
{
    if(! finished) return;
}];

和停止动画使用这样的:

And to stop the animation use this:

[view.layer removeAllAnimations];

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

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