Wednesday, June 12, 2013

CATransaction animationTimingFunction example in Objective C (iOS).

CATransaction animationTimingFunction

Returns the timing function used for all animations within this transaction group.

+ (CAMediaTimingFunction *)animationTimingFunction

Return Value
An instance of CAMediaTimingFunction.

Discussion of [CATransaction animationTimingFunction]
This is a convenience method that returns the CAMediaTimingFunction for the valueForKey: value returned by the kCATransactionAnimationTimingFunction key.

CATransaction animationTimingFunction example.
[CATransaction begin];
CATransaction.animationTimingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
CATransaction.animationDuration = (viewBounds.size.width + box.frame.size.width) / pixelsPerSecond;
// and the layer should cross the viewport to outside of it, too
box.position = CGPointMake(-box.frame.size.width, y);
[CATransaction commit];

Example of [CATransaction animationTimingFunction].
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"path"];
animation.duration = [CATransaction animationDuration];
animation.timingFunction = [CATransaction animationTimingFunction];
animation.fromValue = (id)oldPath;
animation.toValue = (id)path;
[self addAnimation:animation forKey:@"pathAnimation"];

End of CATransaction animationTimingFunction example article.