PQStuckPointLoadingView.swift 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //
  2. // PQStuckPointLoadingView.swift
  3. // PQSpeed
  4. //
  5. // Created by SanW on 2021/5/24.
  6. // Copyright © 2021 BytesFlow. All rights reserved.
  7. //
  8. import Kingfisher
  9. import UIKit
  10. import BFCommonKit
  11. class PQStuckPointLoadingView: UIView {
  12. var cancelHandle: ((_ sender: UIButton) -> Void)?
  13. /// 同步进度显示
  14. lazy var loadingView: UIImageView = {
  15. let loadingView = UIImageView()
  16. loadingView.tintColor = UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue)
  17. let data = try? Data(contentsOf: URL(fileURLWithPath: currentBundlePath()!.path(forResource: "stuckPoint_edit_loading", ofType: ".gif")!))
  18. if data != nil {
  19. PQPHAssetVideoParaseUtil.parasGIFImage(data: data!, isRenderingColor: UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue)) { _, images, duration in
  20. loadingView.displayGIF(data: nil, images: images, repeatCount: .max, duration: duration ?? 2)
  21. }
  22. }
  23. return loadingView
  24. }()
  25. lazy var navBarLeftBtn: UIButton = {
  26. let navBarLeftBtn = UIButton(type: .custom)
  27. navBarLeftBtn.frame = CGRect(x: 0, y: cDevice_iPhoneStatusBarHei, width: cDefaultMargin * 4, height: cDefaultMargin * 4)
  28. navBarLeftBtn.imageEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: -5, right: 0)
  29. navBarLeftBtn.imageEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: -5, right: 0)
  30. navBarLeftBtn.tintColor = PQBFConfig.shared.styleTitleColor
  31. navBarLeftBtn.setImage(UIImage.moduleImage(named: "icon_detail_back", moduleName: "BFFramework",isAssets: false)?.withRenderingMode(.alwaysTemplate), for: .normal)
  32. navBarLeftBtn.addTarget(self, action: #selector(cancelDownload(sender:)), for: .touchUpInside)
  33. return navBarLeftBtn
  34. }()
  35. override init(frame: CGRect) {
  36. super.init(frame: frame)
  37. backgroundColor = UIColor.init(red: 1, green: 1, blue: 1, alpha: 0.5)
  38. addSubViews()
  39. addLayout()
  40. }
  41. required init?(coder _: NSCoder) {
  42. fatalError("init(coder:) has not been implemented")
  43. }
  44. override func layoutSubviews() {
  45. super.layoutSubviews()
  46. }
  47. func addSubViews() {
  48. addSubview(loadingView)
  49. addSubview(navBarLeftBtn)
  50. }
  51. func addLayout() {
  52. loadingView.snp.makeConstraints { make in
  53. // make.top.equalToSuperview().offset(cScreenWidth / 2.0 + cDevice_iPhoneStatusBarHei)
  54. make.centerX.equalTo(cScreenWidth / 2.0)
  55. make.centerY.equalTo(cScreenHeigth / 2.0)
  56. make.width.height.equalTo(cDefaultMargin * 10)
  57. }
  58. }
  59. func show() {
  60. if self.superview != nil {
  61. return
  62. }
  63. UIApplication.shared.keyWindow?.addSubview(self)
  64. let data = try? Data(contentsOf: URL(fileURLWithPath: currentBundlePath()!.path(forResource: "stuckPoint_edit_loading", ofType: ".gif")!))
  65. if data != nil {
  66. PQPHAssetVideoParaseUtil.parasGIFImage(data: data!, isRenderingColor: UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue)) { _, images, duration in
  67. self.loadingView.displayGIF(data: nil, images: images, repeatCount: .max, duration: duration ?? 2)
  68. }
  69. }
  70. }
  71. /// 移除视图
  72. /// - Returns: <#description#>
  73. func removeMarskView() {
  74. if self.superview != nil {
  75. removeFromSuperview()
  76. }
  77. }
  78. @objc func cancelDownload(sender: UIButton) {
  79. if cancelHandle != nil {
  80. cancelHandle!(sender)
  81. removeMarskView()
  82. }
  83. }
  84. deinit {
  85. BFLog(message: "销毁加载中视图")
  86. }
  87. }