【问题标题】:lottie animation not working in UIView iOS乐天动画在 UIView iOS 中不起作用
【发布时间】:2018-06-07 09:05:31
【问题描述】:

这是我的视图控制器

 class ViewController: UIViewController {

        var index = 0
        @IBOutlet weak var lottieView: UIView!
        fileprivate let lottieTouchIdAnimationName = "01_touchId_validation"
        fileprivate let lottieFaceIdAnimationName = "01_faceId_validation"
         @IBOutlet weak var label: UILabel!
        var onBoardingCompletionBlock: ((Bool, Bool?) -> Void)?
        var authenticationResponse: Bool!


        override func viewDidLoad() {
            super.viewDidLoad()

            setupView()
        }


        func setupView() {

            var animationName = ""
            switch index {
            case 0:
                animationName = lottieFaceIdAnimationName
                label.text = "anim 0"
            default:
                animationName = lottieTouchIdAnimationName
                label.text = "anim 1"
            }

            _ = LottieView(in: lottieView,
                           bundle: Bundle.main,
                           name: animationName,
                           velocity: 1.0,
                           loop: false) {[unowned self] _ in
                            self.animationEnded()
            }
        }
        func animationEnded() {
            if let onBoardingCompletionBlock = onBoardingCompletionBlock {
                onBoardingCompletionBlock(true, self.authenticationResponse)
                dismiss(animated: true, completion: nil)
            } else {

            }
        }
    }

所有出口连接的故事板:

我已经安装了 pod,并且资产都在 XCAssets 中可用

【问题讨论】:

  • 在哪里添加LOTAnimationView???
  • lottie 视图未正确初始化。

标签: ios swift lottie


【解决方案1】:

试试这个:

class HmePaymentStatusVC: UIViewController {
    var animationView = LOTAnimationView(name: "lottie_animation_file")

    override func viewDidLoad() {
        super.viewDidLoad()
        animate()
    }

    func animate() {
        animationView.frame = view.bounds
        animationView.contentMode = .scaleAspectFit
        animationView.animationSpeed = 0.5
        self.view.addSubview(animationView)
        animView.play()
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-01
    • 1970-01-01
    相关资源
    最近更新 更多