如何检测CATransaction触发的动画的完成情况 [英] how can I detect the completion of an animation triggered by CATransaction

查看:284
本文介绍了如何检测CATransaction触发的动画的完成情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CALayer,我只是在控制器的initWithNibName中创建并添加到我的视图控制器主视图的子视图中:
然后,我执行以下动画:

I have a CALayer which I merely create and add to a subview of my view controller's main view in the controller's initWithNibName: And then, I perform the following animation:

  [CATransaction begin];
  [CATransaction setAnimationDuration:2];
  [logoLayer setOpacity:0];
  [CATransaction commit];

如何判断动画何时完成? performSelector:延迟2秒。方法似乎并不是正确的方法。

How can I tell when this animation is done? the performSelector: delayed by 2 secs. approach doesn't seem "the right way" to go about it.

推荐答案

根据 doc [CATransaction setCompletionBlock:] 可以用于你想要的东西。

According to the doc, [CATransaction setCompletionBlock:] could be used for what you want.

它说


保证完成块对象(在主线程上)被调用为此事务组随后添加的所有动画都已完成(或已被删除。)如果在提交当前事务组之前未添加动画(或者将完成块设置为不同的值),则将立即调用该块。

The completion block object is guaranteed to be called (on the main thread) as soon as all animations subsequently added by this transaction group have completed (or have been removed.) If no animations are added before the current transaction group is committed (or the completion block is set to a different value,) the block will be invoked immediately.

开始动画交易之前,尝试添加类似的东西。

Try adding something like this before you begin the animation transaction.

[CATransaction setCompletionBlock:^{
    // Action after the animation completion
}];

这篇关于如何检测CATransaction触发的动画的完成情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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