how can I detect the completion of an animation triggered by CATransaction

岁酱吖の 提交于 2019-12-01 03:43:48

问题


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];

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.


回答1:


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

It says

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
}];


来源:https://stackoverflow.com/questions/9049410/how-can-i-detect-the-completion-of-an-animation-triggered-by-catransaction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!