0

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

0 回答 0