PQStuckPointLoadingView.swift 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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: Bundle().BF_mainbundle().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().BF_Image(named: "icon_detail_back").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: 0, green: 0, blue: 0, 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.center.equalToSuperview()
  54. make.width.height.equalTo(cDefaultMargin * 10)
  55. }
  56. }
  57. /// 移除视图
  58. /// - Returns: <#description#>
  59. func removeMarskView() {
  60. removeFromSuperview()
  61. }
  62. @objc func cancelDownload(sender: UIButton) {
  63. if cancelHandle != nil {
  64. cancelHandle!(sender)
  65. removeMarskView()
  66. }
  67. }
  68. deinit {
  69. BFLog(message: "销毁加载中视图")
  70. }
  71. }