等待动画在 iOS 中完成? [英] Wait for Animation to finish in iOS?

查看:23
本文介绍了等待动画在 iOS 中完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在动画完成后执行 doSomethingElse.另一个限制是动画代码可以有不同的持续时间.我怎样才能做到这一点?谢谢!

I want to execute doSomethingElse after the animation is finished. Another constraint is that the animation code can be of different duration. How can I do that? thanks!

-(void) doAnimationThenSomethingElse {
  [self doAnimation];
  [self doSomethingElse];
}

例如这不起作用:

animationDuration = 1;
[UIView animateWithDuration:animationDuration
    animations:^{
      [self doAnimation];
    } completion:^(BOOL finished) {
      [self doSomethingElse];
    }
];

推荐答案

当你不是动画的作者时,你可以使用事务完成块获得动画结束时的回调:

When you are not the author of the animation, you can get a callback when the animation ends by using a transaction completion block:

[CATransaction setCompletionBlock:^{
     // doSomethingElse
}];
// doSomething

这篇关于等待动画在 iOS 中完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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