api-UI

swift 实现简单的 json 动画(Lottie)

2020-07-21  本文已影响0人  优优切克闹

json动画优缺点


使用

1.cocoapod导入 pod 'lottie-ios', '~> 3.1.6'
2.需要用到的文件中导入第三方 import Lottie
3.使用
    lazy var sendCardImgView: AnimationView = {
        let lot = AnimationView()
        let bundle = Bundle(for: BrokersViewController.self)
        let animation = Animation.named("气泡弹窗", bundle: bundle)
        //加载本地json
        lot.animation = animation
        // 加载网络json
        //            if let url = URL (string: "https://brokersshow.oss-cn-shenzhen.aliyuncs.com/dev/files/2020/4/21/hccGradeIcon.json") {
        //                Animation.loadedFrom(url: url, closure: { (an) in
        //                    lot.animation = an
        //                }, animationCache: nil)
        //            }
        lot.contentMode = .scaleAspectFill // 填充模式
        lot.loopMode = .playOnce // 动画播放次数
        lot.backgroundBehavior = .pauseAndRestore // 后台模式
        let tap = UITapGestureRecognizer(target: self, action: #selector(self.onTapSendCardImgView(_:)))
        lot.isUserInteractionEnabled = true
        lot.addGestureRecognizer(tap)
        return lot
    }()
// 动画开始
sendCardImgView.play()
// 动画结束
sendCardImgView.stop()

要赞😊

上一篇下一篇

猜你喜欢

热点阅读