开发者

How to check if an CABasicAnimation is applied and running already?

开发者 https://www.devze.com 2023-04-05 21:21 出处:网络
I create开发者_如何学Python a CABasicAnimation and apply it to a layer like this: [rotatedLayer addAnimation:rotationAnimation forKey:@\"transform.rotation.z\"];

I create开发者_如何学Python a CABasicAnimation and apply it to a layer like this:

[rotatedLayer addAnimation:rotationAnimation forKey:@"transform.rotation.z"];

How can I check if the rotatedLayer is already animating on the transform.rotation.z path?


Check the return value of [rotatedLayer animationForKey:@"transform.rotation.z"];.


You can set an ivar such as:

BOOL _animationRunning;

and set the delegate for your animation to be the class you're in and implement the functions:

animationDidStart:(CAAnimation *)anim
animationDidStop:(CAAnimation *)anim finished:(BOOL)flag

and flip the boolean within those callbacks. Ole's method works as well but if you set the beginTime to have a delay or wrap the animation in an CAAnimationGroup to create a delay (a la CAKeyframeAnimation delay before repeating) then you have getting the animationForKey would also return that animation even though it isn't actually "animating".

0

精彩评论

暂无评论...
验证码 换一张
取 消