使用
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()
要赞😊
网友评论