json動(dòng)畫(huà)優(yōu)缺點(diǎn)
使用
1.cocoapod
導(dǎo)入 pod 'lottie-ios', '~> 3.1.6'
2.需要用到的文件中導(dǎo)入第三方 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
// 加載網(wǎng)絡(luò)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 // 動(dòng)畫(huà)播放次數(shù)
lot.backgroundBehavior = .pauseAndRestore // 后臺(tái)模式
let tap = UITapGestureRecognizer(target: self, action: #selector(self.onTapSendCardImgView(_:)))
lot.isUserInteractionEnabled = true
lot.addGestureRecognizer(tap)
return lot
}()
// 動(dòng)畫(huà)開(kāi)始
sendCardImgView.play()
// 動(dòng)畫(huà)結(jié)束
sendCardImgView.stop()
要贊??