同时运行多个CAKeyframeAnimations

时间:2014-11-12 07:50:48

标签: ios objective-c core-animation cakeyframeanimation catransaction

所以我在不同的图层上有2个CAkeyframeanimations,我想让它们同时运行。

以前我尝试使用dispatch_async运行它们。然而它没有奏效,动画仍按顺序运行。

经过一些搜索,我发现我必须使用CATransaction同时运行动画。然而它们仍在按顺序运行。我在这里做错了什么。

[CATransaction begin];
self.btn1.frame = bezierPathPoint;
CAKeyframeAnimation* keyframeAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
keyframeAnimation.duration = 1.5;
keyframeAnimation.path = [bezierPath CGPath];
keyframeAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
[self.btn1.layer addAnimation:keyframeAnimation forKey:@"position"];

self.btn3.frame = bezierPathPoint2;
CAKeyframeAnimation* keyframeAnimation2 = [CAKeyframeAnimation animationWithKeyPath:@"position"];
keyframeAnimation.duration = 1.5;
keyframeAnimation.path = [bezierPath CGPath];
keyframeAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
[self.btn3.layer addAnimation:keyframeAnimation2 forKey:@"position"];

[CATransaction commit];

0 个答案:

没有答案