CABasicAnimation resets to initial value after animation completes

Nilesh Ukey picture Nilesh Ukey · May 19, 2011 · Viewed 52.9k times · Source

I am rotating a CALayer and trying to stop it at its final position after animation is completed.

But after animation completes it resets to its initial position.

(xcode docs explicitly say that the animation will not update the value of the property.)

any suggestions how to achieve this.

Answer

Nilesh Ukey picture Nilesh Ukey · May 20, 2011

Here's the answer, it's a combination of my answer and Krishnan's.

cabasicanimation.fillMode = kCAFillModeForwards;
cabasicanimation.removedOnCompletion = NO;

The default value is kCAFillModeRemoved. (Which is the reset behavior you're seeing.)