0

我正在使用适用于 iOS 的 Lottie 库并尝试以 .json 格式加载动画下载LottieFiles

我在viewDidLoad()方法中使用此代码:

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()

问题:只显示第一帧,但动画不播放。我尝试了几个文件,但结果是一样的。

我正在使用:

  • Xcode 9.1

  • 斯威夫特 4

  • Lottie-ios v2.1.5 (cocoapod)

4

2 回答 2

1

使用内容模式 .scaleAspectFit 而不是 .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()
于 2020-01-27T06:21:37.280 回答
0

尝试在 viewDidAppear 中调用 .play()

于 2017-12-11T22:16:49.373 回答