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

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

问题描述

我希望动画完成后执行doSomethingElse。另一个限制是,动画code可以是不同的持续时间。我该怎么办呢?谢谢!

   - (无效){doAnimationThenSomethingElse
  [个体经营doAnimation]
  [个体经营doSomethingElse]
}

这例如不工作:

  animationDuration = 1;
[UIView的animateWithDuration:animationDuration
    动画:^ {
      [个体经营doAnimation]
    }完成:^(BOOL完){
      [个体经营doSomethingElse]
    }
];


解决方案

当你是不是动画的作者,你可以当动画通过使用交易完成后段结束得到一个回调:

  [CATransaction setCompletionBlock:^ {
     // 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];
}

This for example doesn't work:

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天全站免登陆