0

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)

Claus
  • 5,662
  • 10
  • 77
  • 118

2 Answers2

1

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()
Chetan Hedamba
  • 293
  • 2
  • 9
0

Try calling .play() in viewDidAppear