Solvedlottie ios animation stop after enter background

Lottie-ios Issue

Hello! Sorry you are having an Issue! Please help us make Lottie better by filling everything below out with as much information as you can so we can try to reproduce and fix the issue!

Check these before submitting:

  • Updated to the latest (2.1.3) version of Lottie
  • The issue doesnt involve and Unsupported Feature
  • This issue isnt related to another open issue

This issue is a

  • Non-Crashing (Visual or otherwise) Bug
  • Crashing Bug
  • Feature Request
  • Regression (Something that once worked doesnt work anymore)

What Platform are you on?

  • MacOS (Specify Platform Version)
  • iOS (Specify Platform Version)

Expected Behavior

(Screenshots encouraged)

Actual Behavior

(Screenshots encouraged)

Code Example

Animation JSON

Adding the animation JSON helps us debug the issue faster!

32 Answers

✔️Accepted Answer

Seem we have this to pause in background and restart when it reach foreground animationView.backgroundBehavior = .pauseAndRestore

Other Answers:

I set loopAnimation to YES ,it works fine frist,but when I pressed the home button,and then back the app, the animation stopped

for me, this worked:

override func viewDidLoad() {
        super.viewDidLoad()
        NotificationCenter.default.addObserver(self, selector: #selector(restartAnimation), name: NSNotification.Name.UIApplicationWillEnterForeground, object: nil)
}

@objc func restartAnimation() {
        animation.play()
}

At least it should be a feature that is by default on (auto pause in bg, resume on fg) that could be toggled off as needed.

@vivekjohn this feature was added to the library a few years ago as shown in some of the comments here. The flag is animationView.backgroundBehavior = .pauseAndRestore. I think your comment will just confuse people looking for an answer and we wouldn't want beginners copying all those force unwraps either.

More Issues: