本文介绍了立即调用CATransaction完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在CAAnimation完成后执行完成块。但是,似乎在我的动画完成之前调用了动画块。动画仍然正确发生。
I'm trying to execute a completion-block after my CAAnimation has finished. However, it seems that animation block is called before my animation completes. The animation still happens correctly though.
[CATransaction begin];
[self.view.layer addAnimation:self.dropAndBounceAnimation forKey:@"appearance"];
[CATransaction setCompletionBlock:completionBlock];
[CATransaction commit];
dropAndBounceAnimation是position.y上的CAKeyFrameAnimation,具有固定的持续时间。
The dropAndBounceAnimation is a CAKeyFrameAnimation on position.y, with a fixed duration.
推荐答案
我不确定这是否真的是正确的解决方法,但是通过在添加动画之前设置完成块 对于图层,在正确的时间始终调用完成块。
I'm not sure if this really is the correct fix, but by setting the completion-block before adding the animation for the layer, the completion-block is consistently called at the correct time.
[CATransaction begin];
[CATransaction setCompletionBlock:completionBlock];
[self.view.layer addAnimation:self.dropAndBounceAnimation forKey:@"appearance"];
[CATransaction commit];
这篇关于立即调用CATransaction完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!