Search code examples
iphonecore-animationcakeyframeanimation

CAKeyFrameAnimation not repeat


Hi I have a CAKeyFrameAnimation scale, that makes an object fade down from full size (1) to near nothing (0.01)

Then this is called:

- (void)animationDidStop:(CAKeyframeAnimation *)anim finished:(BOOL)flag
{

 [self setHidden:YES];

}

It seems to hide the object, but not before making it re-appear again as full sized for a split second, which ruins the fade to small/nothing effect :P

How do I stop the animation from going back to frame 1 for the "animationDidStop" is called? Thanks!


Solution

  • I believe you need to set the fillMode property of your animations to kCAFillModeForwards. That should freeze the animations at their end time.

    Another suggestion (and honestly, this is what I'd usually do) is just set the properties of the layer itself to their final position after you've set up the animation. That way when the animation is removed, the layer will still have the final properties as part of its model.