停止基于块的动画链的最佳方法是什么? [英] What is the best way to stop a chain of block based animations

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

问题描述

假设有一系列基于块的动画,如下所示:

Assuming a chain of block based animations like the following:

UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];

//animation 1
[UIView animateWithDuration:2 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
     view.frame = CGRectMake(0, 100, 200, 200);
} completion:^(BOOL finished){

     //animation 2
     [UIView animateWithDuration:2 delay:0 options: UIViewAnimationOptionRepeat |UIViewAnimationOptionAutoreverse animations:^{
          [UIView setAnimationRepeatCount:1.5];
          view.frame = CGRectMake(50, 100, 200, 200);   
     } completion:^(BOOL finished){

          //animation 3
          [UIView animateWithDuration:2 delay:0 options:0 animations:^{
               view.frame = CGRectMake(50, 0, 200, 200);
          } completion:nil];
     }];
}];

阻止这种动画的最佳方法是什么?只需致电

What would be the best way to stop this kind of animation? Just calling

[view.layer removeAllAnimations];

是不够的,因为它只停止当前正在执行的动画块,其余的将按顺序执行。

is not enough, because that stops only the currently executing animation block and the rest will execute in sequence.

推荐答案

您可以参考已完成传入完成块的BOOL 。如果您调用 removeAllAnimations ,则为NO。

You can consult the finished BOOL passed in to your completion blocks. It will be NO in the case that you've called removeAllAnimations.

这篇关于停止基于块的动画链的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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