在Storyboard中使用Auto Layout和LOTAnimationView

7

有没有一种使用自动布局的方法来使用 LOTAnimationView (Lottie 框架)?我尝试在我的故事板中将 UIView 的类设置为 LOTAnimationView,但却得到了 nil IB 插座。

3个回答

9
应该在最新的 Lottie 版本中设置如下:

enter image description here

在这里设置动画名称:

enter image description here

这里是示例代码:

import UIKit
import Lottie

class ViewController: UIViewController {

    @IBOutlet weak var animationView: AnimationView!

    override func viewDidLoad() {
        super.viewDidLoad()

        animationView.play()

    }
}

6

显示图片描述

获取LOTAnimatedControl的输出。

将JSON文件赋值给LOTAnimationView

lot.animationView.setAnimation(named: "checked_done_")

完整示例:

import UIKit
import Lottie

class ViewController: UIViewController {
    @IBOutlet weak var lot: LOTAnimatedControl!
    override func viewDidLoad() {
        super.viewDidLoad()
        lot.animationView.setAnimation(named: "youranimationjsonfile")
        lot.animationView.play()
    }
}

希望这能帮到你。

1
更新最新的Lottie版本,参考Ashish Kakkad的评论。
将类名从LOTAnimatedControl改为AnimationView
然后在Interface Builder中设置属性animationName

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接