views:

333

answers:

1

I've found this code snippet:

[self setValue:direction forKey:@"currentDirection"];

CAKeyframeAnimation * animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
animation.path = path;
animation.duration = grids * gridWidth / [self speed];
animation.fillMode = kCAFillModeForwards;
animation.removedOnCompletion = NO;
animation.delegate = self;
animation.calculationMode = kCAAnimationLinear;
[self addAnimation:animation forKey:@"movement"];
self.position = destination;

[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithFloat:_turn_duration]
                                          forKey:kCATransactionAnimationDuration];
eyes.position = eyeDestination;
pupils.position = pupilDestination;
[CATransaction commit];

CGPathRelease(path);

What's the point of using the CATransaction here?

+1  A: 

To set the duration of the two implicit animations within the transaction to a value different from the duration of the keyframe animation above. The animations inside the transaction will run over _turn_duration seconds, while the keyframe animation will run over grids * gridWidth / [self speed] seconds.

Rob Napier
So the CAKeyframeAnimation is an animation block?
Thanks
No, it's an animation :D An animation is explicitly or implicitly applied to an object. You can group animations together and then explicitly apply them to objects. What you want to do now is spend some time with the Core Animation Programming Guide, particularly starting at the "Animation" chapter and going forward. http://developer.apple.com/documentation/Cocoa/Conceptual/CoreAnimation_guide/Articles/AnimatingLayers.html
Rob Napier