How to check if an CABasicAnimation is applied and running already?
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".
精彩评论