Interpolating the values with a custom function is very easy. But is it bad practice? Should I instead (or in addition) use keyTimes
, timingFunctions
or timingFunction
to explain the animation-curve to the framework? When working with custom animation curves I really don't see why I should use those properties. I want to do this right.
This works just fine. As expected it animates the views-position with a custom cubic-ease-out animation curve:
CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"position.x"];
anim.duration = 5;
NSUInteger numberOfFrames = anim.duration * 60;
NSMutableArray *values = [NSMutableArray new];
for (int i = 0; i < numberOfFrames; i++)
{
CGFloat linearProgress = (double) i / (double) numberOfFrames;
CGPoint position = view.layer.position;
position.x = 10 + (300 * CubicEaseOut(linearProgress));
[values addObject:[NSValue valueWithCGPoint:position]];
}
anim.values = values;
[view.layer addAnimation:anim forKey:@"position"];