Lottie-ios: Animations no longer play after moving to a page in a UIPageViewController

Created on 22 Nov 2019  路  3Comments  路  Source: airbnb/lottie-ios

Check these before submitting:

  • [x] The issue doesn't involve an Unsupported Feature
  • [x] This issue isn't related to another open issue

This issue is a:

  • [x] Non-Crashing Bug (Visual or otherwise)
  • [] Crashing Bug
  • [] Feature Request
  • [x] Regression (Something that once worked, but doesn't work anymore)

Which Version of Lottie are you using?

Lottie 3.1.x

What Platform are you on?

  • [] MacOS
  • [x] iOS

What Language are you in?

  • [x] Swift
  • [] Objective-C

Expected Behavior

Every page of my UIPageViewController has a Lottie Animation in a window at the top of the page. I expect all the animations to play when I move to each next page, and back to previous pages.

Actual Behavior

The animation plays in the first page, but when moving to subsequent pages, or back to the first page, the animations no longer play. It works fine up to v 3.0.6, but stopped working in versions 3.0.7 and 3.1.0 - 3.1.3

Code Example

var animation: AnimationView?
override func viewDidLoad() {
    super.viewDidLoad()

    let animation = AnimationView(name: "MyJLottieJson")
    animation.loopMode = .loop
    animation.contentMode = .scaleAspectFill
    animationView.addSubview(animation)
    self.animation = animation
}

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    animation?.play()
}

Animation JSON

Most helpful comment

try

backgroundBehavior = .pauseAndRestore

All 3 comments

try

backgroundBehavior = .pauseAndRestore

try

backgroundBehavior = .pauseAndRestore

Yes, setting

animation.backgroundBehavior = .pauseAndRestore

did the trick. Thanks!

Describes the behavior of an AnimationView when the app is moved to the background.

The default is pause which pauses the animation when the application moves to
the background. The completion block is called with false for completed.

How is this in anyway obvious? The documentation needs to be updated so that it doesn't just refer to the app going into the background...
Or instead this is a bug, and that is just an awkward workaround?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rdd7 picture rdd7  路  4Comments

petoye picture petoye  路  3Comments

amannayak0007 picture amannayak0007  路  3Comments

albertoNovo picture albertoNovo  路  3Comments

whisterlee picture whisterlee  路  3Comments