lottie动画在UIView iOS中无效

时间:2018-06-07 09:05:31

标签: ios swift lottie

这是我的 Viewcontroller

 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 {

            }
        }
    }

连接所有网点的故事板:

enter image description here

我安装了pod,资源在XCAssets中都可用

1 个答案:

答案 0 :(得分:0)

尝试一下:

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