|
@@ -9,33 +9,60 @@
|
|
import UIKit
|
|
import UIKit
|
|
|
|
|
|
public class PQLoadingHUBView: UIView {
|
|
public class PQLoadingHUBView: UIView {
|
|
- lazy public var loadingImage: UIImageView = {
|
|
|
|
|
|
+ // gif每一帧图
|
|
|
|
+ public var gifImages: [UIImage]?
|
|
|
|
+ // gif播放时长
|
|
|
|
+ public var duration: Double?
|
|
|
|
+
|
|
|
|
+ public lazy var loadingImage: UIImageView = {
|
|
let loadingImage = UIImageView()
|
|
let loadingImage = UIImageView()
|
|
- loadingImage.kf.setImage(with: URL(fileURLWithPath: Bundle.init().BF_mainbundle().path(forResource: "loading_pq", ofType: ".gif")!))
|
|
|
|
|
|
+ loadingImage.tintColor = UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue)
|
|
return loadingImage
|
|
return loadingImage
|
|
}()
|
|
}()
|
|
|
|
|
|
- public override init(frame: CGRect) {
|
|
|
|
|
|
+ override public init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
super.init(frame: frame)
|
|
addSubview(loadingImage)
|
|
addSubview(loadingImage)
|
|
isUserInteractionEnabled = false
|
|
isUserInteractionEnabled = false
|
|
|
|
+ let data = try? Data(contentsOf: URL(fileURLWithPath: Bundle().BF_mainbundle().path(forResource: "stuckPoint_music_loading", ofType: ".gif")!))
|
|
|
|
+ if data != nil {
|
|
|
|
+ PQPHAssetVideoParaseUtil.parasGIFImage(data: data!, isRenderingColor: UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue)) { [weak self] _, images, duration in
|
|
|
|
+ self?.gifImages = images
|
|
|
|
+ self?.duration = duration
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
required init?(coder _: NSCoder) {
|
|
required init?(coder _: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
}
|
|
|
|
|
|
- public override func layoutSubviews() {
|
|
|
|
|
|
+ override public func layoutSubviews() {
|
|
super.layoutSubviews()
|
|
super.layoutSubviews()
|
|
// 334 * 307
|
|
// 334 * 307
|
|
let imageW: CGFloat = 67
|
|
let imageW: CGFloat = 67
|
|
let imageH: CGFloat = 62
|
|
let imageH: CGFloat = 62
|
|
loadingImage.frame = CGRect(x: (frame.width - imageW) / 2, y: (frame.height - imageW) / 2, width: imageW, height: imageH)
|
|
loadingImage.frame = CGRect(x: (frame.width - imageW) / 2, y: (frame.height - imageW) / 2, width: imageW, height: imageH)
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /// 开始加载
|
|
|
|
+ public func loading() {
|
|
|
|
+ loadingImage.displayGIF(data: nil, images: gifImages, repeatCount: .max, duration: duration ?? 2)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// 停止加载
|
|
|
|
+ public func endLoading() {
|
|
|
|
+ loadingImage.removePlayGIF()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override public func removeFromSuperview() {
|
|
|
|
+ loadingImage.removePlayGIF()
|
|
|
|
+ loadingImage.removeFromSuperview()
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
public class PQLoadingHUB: NSObject {
|
|
public class PQLoadingHUB: NSObject {
|
|
- static public let shared = PQLoadingHUB()
|
|
|
|
|
|
+ public static let shared = PQLoadingHUB()
|
|
public let viewTag = 11111
|
|
public let viewTag = 11111
|
|
public var isLoading: Bool = false
|
|
public var isLoading: Bool = false
|
|
|
|
|
|
@@ -47,6 +74,7 @@ public class PQLoadingHUB: NSObject {
|
|
loadingHUB.tag = self!.viewTag
|
|
loadingHUB.tag = self!.viewTag
|
|
window?.addSubview(loadingHUB)
|
|
window?.addSubview(loadingHUB)
|
|
loadingHUB.center = window?.center as! CGPoint
|
|
loadingHUB.center = window?.center as! CGPoint
|
|
|
|
+ loadingHUB.loading()
|
|
self?.isLoading = true
|
|
self?.isLoading = true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -73,6 +101,7 @@ public class PQLoadingHUB: NSObject {
|
|
let loadingHUB: PQLoadingHUBView = PQLoadingHUBView(frame: CGRect(x: hubX, y: hubY, width: 100, height: 100))
|
|
let loadingHUB: PQLoadingHUBView = PQLoadingHUBView(frame: CGRect(x: hubX, y: hubY, width: 100, height: 100))
|
|
loadingHUB.tag = self!.viewTag
|
|
loadingHUB.tag = self!.viewTag
|
|
superView.addSubview(loadingHUB)
|
|
superView.addSubview(loadingHUB)
|
|
|
|
+ loadingHUB.loading()
|
|
self?.isLoading = true
|
|
self?.isLoading = true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -91,11 +120,11 @@ public class PQLoadingHUB: NSObject {
|
|
super.init()
|
|
super.init()
|
|
}
|
|
}
|
|
|
|
|
|
- public override func copy() -> Any {
|
|
|
|
|
|
+ override public func copy() -> Any {
|
|
return self
|
|
return self
|
|
}
|
|
}
|
|
|
|
|
|
- public override func mutableCopy() -> Any {
|
|
|
|
|
|
+ override public func mutableCopy() -> Any {
|
|
return self
|
|
return self
|
|
}
|
|
}
|
|
}
|
|
}
|