Object retaining position after CAKeyframeAnimation

Hello All,

I have an imageView that I am moving around with a CAKeyframeAnimation. After the animation completes the object warps back to the place it was before the animation started but i want to have it stay where it was animated to. I am reading through the docs but I am not seeing what I am doing wrong; any help you could offer would be much appreciated. Thank you.

Mac OS X (10.5.4)

Posted on Oct 13, 2008 5:52 PM

Reply
8 replies

Oct 13, 2008 7:48 PM in response to brackeen

I understand what this is supposed to do but I keep getting errors when I try to add this last line (trying every relevant thing I can think of for the paramater of setValue and forKeyPath

I apologize for my apparent stupidity but can you help me a little more specifically? My relevant code is:

CGMutablePathRef thePath = CGPathCreateMutable();
CGPathMoveToPoint(thePath,NULL,160,375);
CGPathAddCurveToPoint(thePath,NULL,160,375,
160,100,
160.0,100);

CAKeyframeAnimation *theAnimation;

theAnimation=[CAKeyframeAnimation animationWithKeyPath:@"position"];
theAnimation.path=thePath;
theAnimation.duration=3.0;
CFRelease(thePath);
[pictureView.layer addAnimation:theAnimation forKey:@"position"];

Oct 28, 2008 3:23 AM in response to scotopia

I had the same problem. First I tried solving it by setting the fill mode:

{{{
bounceAnimation.fillMode = kCAFillModeForwards;
}}}

But this did not do the job (perhaps it will work for you)

So what I ended up doing is:
1. Using a timing array, which defines how log it takes from one key frame to another: bounceAnimation.keyTimes = keyTimesArray; (where keyTimesArray is a simple mutable array with NSNumber objects with valies [0..1]
2. At the end of the animation added another keyframe and set the timing to a very long time (so it does stay there for a very long time)

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Object retaining position after CAKeyframeAnimation

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.