我可以在CATransaction期间设置每帧更新执行的块吗?

时间:2016-02-24 21:47:37

标签: ios core-animation

我希望在动画时更新CATransformLayer的子图层的颜色。有没有办法在动画CATransaction的持续时间内设置块在每次帧更新时执行?如果不是,在动画期间获取子图层颜色的最佳方法是什么?

[CATransaction begin];
[CATransaction setAnimationDuration:duration];
// The imaginary functionality of the following imaginary code is what I want to implement--though not at all in any form that resembles its imaginary form below
[CATransaction setBlockThatExecutesPerFrameUpdate:^{
    for ( CALayer *layer in self.transformLayer.sublayers )
        [layer doSomethingWith:layer.presentationLayer.transform];
}];
// What I imagine ends here
self.transformLayer.transform = [self sideTransform];
[CATransaction commit];

1 个答案:

答案 0 :(得分:2)

动画发生在主线程的自己的进程("动画服务器")中。没有任何通知回复给你的"在动画期间以每帧为基础的代码,这是正确的,因为这样可能会无法忍受地减慢动画的速度,更不用说可能会干扰您的代码。如果要在进行其他动画的同时更改颜色,只需使用与其他动画相同的持续时间为颜色更改设置动画。你可以要求几个动画,它们将在动画服务器获得控制权时一起发生。

相关问题