Running multiple CAKeyframeAnimations at the same time

286 views Asked by At

So i have 2 CAkeyframeanimations on different layers and i want them to run simultaneously.

Previously i tried running them from using dispatch_async. However it didn't worked and the animation were still running in sequence.

After a bit of search i found that i must use CATransaction to run animations simultaneously. However they are still running in sequence.What is it i am doing wrong here.

[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

There are 0 answers