Q:

Stopping a looped CAAnimation after current cycle has finished

In my application, I have some CAAnimations which loop infinitely (animation.repeatCount = HUGE_VALF).
What I want to do is remove those animations, after the current cycle has finished. -[CALayer removeAnimationForKey:] makes the layer jump to it's normal position, which I want to prevent.
What i could do is: get the current transform of the layers presentation layer (i'm doing a rotation), calculate the time to finish the animation, remove the animation, and add another animation with a repeatCount of one, but that seems unnecessary complicated and i feel there must be a more simple way to do this. 
So, any suggestions?

A:

How about using an animation whose completion block invokes the animation again, based on a flag? When you want to make the animation sequence stop, set the flag to false. The completion block will see that the repeat flag is false, and stop at the end of the last cycle.
After committing your animation, you should change the transform to its end value. If you're doing view animation, just set the transform to its final value. That way, once the animation is removed, it will stay at the end state.
If you're using layer transforms, you'll need to put the code that sets the transform to its final state in a CATransactionBegin/ with [CATransaction setDisableActions: YES], so that change is not implicitly animated.

