0

Setup animation:

CABasicAnimation *noteAnimation = [CABasicAnimation animation];
noteAnimation.keyPath = @"position.x";
noteAnimation.byValue = [NSNumber numberWithFloat:CGRectGetWidth(self.view.frame) - 50];
noteAnimation.duration = 1.f;
noteAnimation.fillMode = kCAFillModeBoth;
noteAnimation.removedOnCompletion = NO;
noteAnimation.autoreverses = YES;
noteAnimation.repeatCount = HUGE;
noteAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
[self.greenSquareView.layer addAnimation:noteAnimation forKey:@"noteAnimation"];

To pause the acting animation I use:

CFTimeInterval pausedTime = [view.layer convertTime:CACurrentMediaTime() fromLayer:nil];
view.layer.speed = 0.0;
view.layer.timeOffset = pausedTime;

But in this case view stops with bouncing.

Full project on BitBucket.

enter image description here

bacc3
  • 1
  • 2
  • You should always ask a question. Since `speed` and `timeOffset` are both not animatable properties I would try to `removeAllAnimations()` and set the current model value of the layer to the value of the display layer (in this case the position). You have to begin a new `CATransaction` though and disable animations with `CATransaction.setDisableActions(false)`, then sync the position with the display layer, then commit the transaction. – fruitcoder Jan 17 '17 at 21:19
  • I don't want animate `speed` and `timeOffset` (i added some info in my question). I use this properties for pausing animation. I tried your method - it's not work (problem with bouncing reproduced). – bacc3 Jan 19 '17 at 09:14
  • I downloaded your project and it pauses without a bounce o.O – fruitcoder Jan 19 '17 at 16:15
  • First of all: you see bounce on an attached gif? (i record this from my iphone). I did not see bouncing in a simulator. But on a real device (iphone 6, ios 10.1) this "bug" reproduced. – bacc3 Jan 19 '17 at 17:45
  • Yes on the gif I definitely see what you mean. I'll try to reproduce on real device after work. – fruitcoder Jan 20 '17 at 10:32
  • @fruitcoder any news? – bacc3 Jan 23 '17 at 07:46
  • I could reproduce it on my device sometimes. It's so subtle that it's hard to see sometimes, but it's there... The way you pause/resume the animation is exactly how Apple describes it in the technical note QA1673, which is summarised in this post http://stackoverflow.com/questions/2306870/is-there-a-way-to-pause-a-cabasicanimation . Maybe you can ask for help in this thread, because I really don't have any clue why this happens :/ – fruitcoder Jan 23 '17 at 09:24

0 Answers0