在故事板中使用LOTAnimationView和自动布局

时间:2018-04-06 18:50:43

标签: ios swift autolayout uistoryboard lottie

有没有办法在自动布局中使用LOTAnimationView(Lottie框架)?我尝试在我的故事板中将UIView的类设置为LOTAnimationView,但获得nil IB插座..

3 个答案:

答案 0 :(得分:5)

enter image description here

采取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 :(得分:1)

应该在最新的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()

    }
}

答案 2 :(得分:0)

使用Ashish Kakkad的评论更新最新的Lottie版本。

更改类名AnimationView而不是LOTAnimatedControl

,然后在Interface Builder中设置属性animationName