Wednesday, June 12, 2013

CATransaction kCATransactionAnimationTimingFunction example in Objective C (iOS).

CATransaction kCATransactionAnimationTimingFunction

Transaction properties
These constants define the property keys used by valueForKey: and setValue:forKey:.

NSString * const kCATransactionAnimationDuration;
NSString * const kCATransactionDisableActions;
NSString * const kCATransactionAnimationTimingFunction;
NSString * const kCATransactionCompletionBlock;

Duration, in seconds, for animations triggered within the transaction group. The value for this key must be an instance of NSNumber.
If YES, implicit actions for property changes made within the transaction group are suppressed. The value for this key must be an instance of NSNumber.
An instance of CAMediaTimingFunction that overrides the timing function for all animations triggered within the transaction group.
A completion block object that is guaranteed to be called (on the main thread) as soon as all animations subsequently added by this transaction group have completed (or have been removed.) If no animations are added before the current transaction group is committed (or the completion block is set to a different value,) the block will be invoked immediately.

CATransaction kCATransactionAnimationTimingFunction example.
[CATransaction begin];

[CATransaction setValue:kCAMediaTimingFunctionEaseInEaseOut forKey:kCATransactionAnimationTimingFunction];
[CATransaction setAnimationDuration:1.0];
theChicken.position = CGPointMake(225, 144);

[CATransaction commit];

Example of [CATransaction kCATransactionAnimationTimingFunction].
[CATransaction begin];

[CATransaction setValue:[CAMediaTimingFunction

for (CALayer *layer in self.layers){
    CABasicAnimation *shadowAnimation =
    [CABasicAnimation animationWithKeyPath:@"shadowPath"];

    shadowAnimation.fromValue =
        (id)[UIBezierPath bezierPathWithRect:layer.bounds].CGPath;
    shadowAnimation.timingFunction =
        [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
    layer.frame = rectFinal;
    shadowAnimation.toValue =
        (id)[UIBezierPath bezierPathWithRect:layer.bounds].CGPath;
    layer.shadowPath =
        [UIBezierPath bezierPathWithRect:layer.bounds].CGPath;
    [layer addAnimation:shadowAnimation forKey:nil];
[CATransaction commit];

End of CATransaction kCATransactionAnimationTimingFunction example article.