Restoring animation where it left off when app resumes from background

后端 未结 10 1316
广开言路
广开言路 2020-11-28 18:57

I have an endlessly looping CABasicAnimation of a repeating image tile in my view:

a = [CABasicAnimation animationWithKeyPath:@\"position\"];
a         


        
10条回答
  •  悲哀的现实
    2020-11-28 19:15

    I can't comment so I will add it as an answer.

    I used cclogg's solution but my app was crashing when the animation's view was removed from his superview, added again, and then going to background.

    The animation was made infinite by setting animation.repeatCount to Float.infinity.
    The solution I had was to set animation.removedOnCompletion to false.

    It's very weird that it works because the animation is never completed. If anyone has an explanation, I like to hear it.

    Another tip: If you remove the view from its superview. Don't forget to remove the observer by calling NSNotificationCenter.defaultCenter().removeObserver(...).

提交回复
热议问题