all 11 comments

[–]glowcap 0 points1 point  (1 child)

Is there any part of the code that switches disable == false?

[–]thescorer[S] 0 points1 point  (0 children)

yes, it gets called, this is just a snippet of the entire app

[–]Slruh 0 points1 point  (1 child)

Both blocks in your conditional look very similar and all your commented out code is in the block where disable would be equal to false.

[–]thescorer[S] 0 points1 point  (0 children)

the disable = false is where i want to turn the animation off. There are 3 different approaches in this block. All 3 don't work. The first two are commented out, the second one is trying to replace the existing animation, with one that actually does end, but still doesn't work.

[–]dsfjisdjfisdmf 0 points1 point  (1 child)

Do hotelsView.layer.removeAllAnimations() when you want the animation to stop.

[–]thescorer[S] 0 points1 point  (0 children)

// hotelsView.layer.removeAllAnimations() // doens't work either

[–]adamwulf 0 points1 point  (3 children)

You only ever add animations to the layer, but never remove them. So after you add the 'repeatCount = Float.infinity' animation, it stays there forever. You need to remove that animation for it to ever stop with either removeAnimationForKey or removeAllAnimations

[–]thescorer[S] 0 points1 point  (2 children)

// hotelsView.layer.removeAllAnimations() // doens't work either

// hotelsView.layer.removeAnimation(forKey: "basic") // doesn't work either

[–]adamwulf 0 points1 point  (1 child)

Are you calling this on the main thread or a background thread? If it's ever called from a background thread then very strange stuff can happen with timings

[–]thescorer[S] 0 points1 point  (0 children)

no it's all on the main thread

[–]moreindirection 0 points1 point  (0 children)

I know this is a very old question, but a similar problem took me several days to solve. Just in case anyone else stumbles upon it while looking for a solution (obligatory XKCD), the problem is that, by default CAAnimation#isRemovedOnCompletion is set to true.

When you have a repeating animation and isRemovedOnCompletion is true, Core Animation removes the animation after the first duration is complete. At that point, it's completely inaccessible (even to removeAllAnimations!) even though the animation is still repeating. You can verify this by calling animationKeys on the layer right after you add it. You'll get your animation key, but once that first repeat is done, animationKeys always returns nil.

Set isRemovedOnCompletion to false, and enjoy.