CABasicAnimation Interpolation

In my previous post, I detailed how you have to specify to and from values for a basic animation on a property. Using those two values, the animation should be able to interpolate the actual values of a property at any point.

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
animation.delegate = self;
animation.fromValue = [NSValue valueWithCGPoint:layer.position];
// move the x position by delta
animation.toValue = [NSValue valueWithCGPoint:CGPointMake(layer.position.x + delta, layer.position.y)];

// later during the animation
NSValue *currentValue = [(CABasicAnimation *)[aLayer animationForKey:@"position"] byValue];

For some reason, this doesn’t work, and you have to grab the value from the presentation layer instead.

Advertisements

Posted on February 25, 2011, in Code and tagged , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: