所以我在不同的图层上有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];