views:

563

answers:

1

Hi,

I'm trying to animate a layer's position. It animates, but it's frame property is not updated at the end of the animation, it seems only its presentationLayer is. Here's what I'm doing:

CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint   (path, NULL, layer.frame.origin.x, layer.frame.origin.y);
CGPathAddLineToPoint(path, NULL, 20,  20);
CGPathAddLineToPoint(path, NULL, 20,  460);
CGPathAddLineToPoint(path, NULL, 300, 460);

CAKeyframeAnimation* animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
animation.path = path;
animation.calculationMode = kCAAnimationPaced;
animation.repeatCount = 0;
animation.autoreverses = NO;

CAAnimationGroup *theGroup = [CAAnimationGroup animation];
theGroup.animations = [NSArray arrayWithObject:animation];
theGroup.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
theGroup.duration = 2;
theGroup.removedOnCompletion = NO;
theGroup.fillMode = kCAFillModeForwards;
CFRelease(path);

[layer addAnimation:theGroup forKey:@"animatePosition"];

After the animation completes, the layer is sitting at its correct destination, but when I query its frame value, it says it's still at its original location! When/where/how are we supposed to bring the frame property in sync with the presentationLayer frame property of the layer?

Thanks

+1  A: 

Animation doesn't actually change any values on the underlying layer. To update the actual frame value, immediately after your last line, just set the frame to the new value. Then you can probably get rid of the removedOnCompletion = NO;

As long as the animation isn't additive, the animation will run based on the data you entered, and setting the actual frame will have no effect on the display until the animation completes.

Ed Marty