Hot questions for Using Lottie in after effects

Top 10 Java Open Source / Lottie / after effects

Question:

I'm using the Lottie library for iOS and trying to load an animation in .json format downloaded LottieFiles.

I'm using this code in the viewDidLoad() method:

let animationView = LOTAnimationView(name: "infinite_rainbow")
animationView.loopAnimation = true
animationView.frame = CGRect(x: 0, y: 0, width: 400, height: 400)
animationView.center = self.view.center
animationView.contentMode = .scaleAspectFill
view.addSubview(animationView)
animationView.play()

Problem: just the first frame gets displayed, but the animation doesn't play. I have tried several files but the result is the same.

I'm using:

  • Xcode 9.1

  • Swift 4

  • Lottie-ios v2.1.5 (cocoapod)


Answer:

use content mode .scaleAspectFit instead of .scaleAspectFill

    let animationView = LOTAnimationView(name: "infinite_rainbow")
    animationView.loopAnimation = true
    animationView.frame = CGRect(x: 0, y: 0, width: 400, height: 400)
    animationView.center = self.view.center
    animationView.contentMode = .scaleAspectFit
    view.addSubview(animationView)
    animationView.play()