我为什么要在动画中使用CATransaction?

时间:2009-07-21 21:37:40

标签: iphone cocoa-touch uikit

我找到了这段代码:

[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);

在这里使用CATransaction有什么意义?

1 个答案:

答案 0 :(得分:2)

将事务中两个隐式动画的持续时间设置为与上面关键帧动画的持续时间不同的值。事务中的动画将运行_turn_duration秒,而关键帧动画将运行grids * gridWidth / [self speed]秒。