0

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];
Win Coder
  • 6,628
  • 11
  • 54
  • 81
  • Do they really run in sequence? I would expect them to run at the same time already. – David Rönnqvist Nov 12 '14 at 08:30
  • unfortunately they are running in sequence in addition to flickering – Win Coder Nov 12 '14 at 08:35
  • the first one btn animates and at the same time second btn immeadietly moves to its final position without animation. And then once the animation for the first btn is completed. it moves onto the path of the second btn and animates – Win Coder Nov 12 '14 at 08:40
  • The transaction you are doing is weird. You are explicitly adding the animations, so there is no reason to use a transaction. – David Rönnqvist Nov 12 '14 at 09:21
  • 1
    well i finally solved the problem it was unrelated to CATransaction or CAKeyframeAnimation. I was using many btns on the screen and basically was using the wrong reference. – Win Coder Nov 12 '14 at 09:53

0 Answers0