1.写了一个简单的swift 文件YYJsonAnimaView,可以在oc 中使用(oc 怎么使用swift 文件的文章很多,可以自己搜索一下) ?
import Foundation
import Lottie? ? //swift oc 用的时候(CompatibleAnimationView)只有本地的,没有服务端远程加载,纠结。。。。。 2.5.3(oc最新的)版本的有一些json动画的播放有问题,不兼容;所以弄了一个swift 版本的就可以了
class YYJsonAnimaView: NSObject {
?? ?
? ? @objc public final var mm_jsonSONAnimaView = AnimationView()
? ? @objc public final var isStop = Bool()
? ? @objc
? ? public var loopAnimationCount: CGFloat = 0 { //次数
? ? ? didSet {
? ? ? ? mm_jsonSONAnimaView.loopMode = loopAnimationCount == -1 ? .loop : .repeat(Float(loopAnimationCount))
? ? ? }
? ? }
? ? @objc func mm_file(path:String) -> (AnimationView?) { //加载本地的,bundel是main
?? ? ? ?
? ? ? ? mm_jsonSONAnimaView = AnimationView(filePath: path)
? ? ? ? return mm_jsonSONAnimaView
? ? }
? ? @objc func file(name:String) -> (AnimationView?) { //加载本地的,bundel是main
? ? ? ? mm_jsonSONAnimaView = AnimationView(name: name)
? ? ? ? return mm_jsonSONAnimaView
? ? }
?? ?
? ? @objc func bundle_file(name:String,bundle: Bundle) -> (AnimationView?) {
//? ? ? ? mm_jsonSONAnimaView = AnimationView()
? ? ? ? let animation = Animation.named(name, subdirectory: "allPlayJson")
? ? ? ? print("oldValue")
? ? ? ? mm_jsonSONAnimaView.animation = animation
? ? ? ? return mm_jsonSONAnimaView
? ? }
? ? //加载服务端的
? ? @objc func url(name:URL,completion: LottieCompletionBlock? = nil) -> (AnimationView?) {
? ? ? ? mm_jsonSONAnimaView = AnimationView(url:name, closure: { (error) in
? ? ? ? ? ? if let _ = error {
? ? ? ? ? ? ? ? print("网络动画加载失败~~")
? ? ? ? ? ? ? ? completion!(false)
? ? ? ? ? ? } else {
//? ? ? ? ? ? ? ? print("aass动画加载成功~~")
//? ? ? ? ? ? ? ? if self.isStop == false {
? ? ? ? ? ? ? ? ? ? completion!(true)
//? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? })
? ? ? ? return mm_jsonSONAnimaView
? ? }
? ? @objc func play(completion: LottieCompletionBlock? = nil) -> Void {
? ? ? ? mm_jsonSONAnimaView.play { (isu) in
? ? ? ? ? ? if Thread.isMainThread {
? ? ? ? ? ? ? ? completion!(isu)
? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? DispatchQueue.main.async {
? ? ? ? ? ? ? ? ? ? completion!(isu)
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
?? ? ? ? ? ?
? ? ? ? }
? ? }
? ? @objc func pause() -> Void {
? ? ? ? mm_jsonSONAnimaView.pause();
? ? }
? ? @objc func stop() -> Void {
? ? ? ? isStop = true;
? ? ? ? mm_jsonSONAnimaView.stop();
? ? }
? ? @objc func removeFromSuperview() -> Void {
? ? ? ? mm_jsonSONAnimaView.removeFromSuperview()
? ? }
? ? @objc func play() -> Void {
? ? ? ? mm_jsonSONAnimaView.play()
? ? }
}
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,会注明原创字样,如未注明都非原创,如有侵权请联系删除!;3.作者投稿可能会经我们编辑修改或补充;4.本站不提供任何储存功能只提供收集或者投稿人的网盘链接。 |