0

I have animated a UIScrollView this way:

let anim = CAKeyframeAnimation()
anim.keyPath = "bounds.origin.x"
anim.values = self.animValues
anim.keyTimes = self.animKeyTimes
anim.duration = self.animDuration
anim.additive = true
myScrollView.layer.addAnimation(anim, forKey: "move")

Then when the user taps a Cancel I tried this:

myScrollView.layer.removeAnimationForKey("move")
myScrollView.layer.removeAllAnimations()

Neither one works. I also tried setting anim.duration = 0.0. That had no effect. I can't try doing anything with myScrollView.layer.presentationLayer() because presentationLayer() is nil.

The animations do not need to be paused. They can be completely halted and discarded. They are never restarted.

These animations can be 30 seconds or more. Forcing the user to wait until it's finished is not good UX/UI.

Any help would be greatly appreciated.

Thanks,

David

David Reich
  • 709
  • 6
  • 14
  • are you doing anything in completion handler of animation ? means when complete animation its start again ? – Ketan Parmar May 12 '16 at 06:09
  • Lion, I don't have a completion handler. I don't want to start again. The animation is in time with another process which lasts the same amount of time. I don't need to detect the end of both. Thanks, David – David Reich May 12 '16 at 06:25

2 Answers2

0

You can try setting animation speed to zero

myScrollView.layer.speed = 0.0

Try anim.keyPath = "position.x" instead of "bounds.origin.x". This worked for me with layer.removeAllAnimations()

stefos
  • 1,235
  • 1
  • 10
  • 18
  • stefos, But I want to actually stop it and make it go away. For instance if I have a 30 second animation and the user clicks cancel after 10 seconds. I want them to be able to hit start and start from the beginning again. I do not want them to resume. – David Reich May 12 '16 at 12:54
  • And "position.x" doesn't stop any more than "bounds.origin.x" does. – David Reich May 12 '16 at 15:04
0

I had to rebuild my project file for a different problem, and when I tried this again it worked the way it's supposed to!

That's at least the third time I've had to rebuild the project file for this app. I must be doing something right!

David Reich
  • 709
  • 6
  • 14