PQStuckPointLoadingView.swift 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. class PQStuckPointLoadingView: UIView {
  11. var cancelHandle: ((_ sender: UIButton) -> Void)?
  12. /// 同步进度显示
  13. lazy var loadingView: UIImageView = {
  14. let loadingView = UIImageView()
  15. loadingView.tintColor = UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue)
  16. let data = try? Data(contentsOf: URL(fileURLWithPath: Bundle().BF_mainbundle().path(forResource: "stuckPoint_edit_loading", ofType: ".gif")!))
  17. if data != nil {
  18. PQPHAssetVideoParaseUtil.parasGIFImage(data: data!, isRenderingColor: UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue)) { _, images, duration in
  19. loadingView.displayGIF(data: nil, images: images, repeatCount: .max, duration: duration ?? 2)
  20. }
  21. }
  22. return loadingView
  23. }()
  24. lazy var navBarLeftBtn: UIButton = {
  25. let navBarLeftBtn = UIButton(type: .custom)
  26. navBarLeftBtn.frame = CGRect(x: 0, y: cDevice_iPhoneStatusBarHei, width: cDefaultMargin * 4, height: cDefaultMargin * 4)
  27. navBarLeftBtn.imageEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: -5, right: 0)
  28. navBarLeftBtn.imageEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: -5, right: 0)
  29. navBarLeftBtn.tintColor = PQBFConfig.shared.styleTitleColor
  30. navBarLeftBtn.setImage(UIImage().BF_Image(named: "icon_detail_back").withRenderingMode(.alwaysTemplate), for: .normal)
  31. navBarLeftBtn.addTarget(self, action: #selector(cancelDownload(sender:)), for: .touchUpInside)
  32. return navBarLeftBtn
  33. }()
  34. override init(frame: CGRect) {
  35. super.init(frame: frame)
  36. backgroundColor = UIColor.init(red: 0, green: 0, blue: 0, alpha: 0.5)
  37. addSubViews()
  38. addLayout()
  39. }
  40. required init?(coder _: NSCoder) {
  41. fatalError("init(coder:) has not been implemented")
  42. }
  43. override func layoutSubviews() {
  44. super.layoutSubviews()
  45. }
  46. func addSubViews() {
  47. addSubview(loadingView)
  48. addSubview(navBarLeftBtn)
  49. }
  50. func addLayout() {
  51. loadingView.snp.makeConstraints { make in
  52. make.center.equalToSuperview()
  53. make.width.height.equalTo(cDefaultMargin * 10)
  54. }
  55. }
  56. /// 移除视图
  57. /// - Returns: <#description#>
  58. func removeMarskView() {
  59. removeFromSuperview()
  60. }
  61. @objc func cancelDownload(sender: UIButton) {
  62. if cancelHandle != nil {
  63. cancelHandle!(sender)
  64. removeMarskView()
  65. }
  66. }
  67. deinit {
  68. BFLog(message: "销毁加载中视图")
  69. }
  70. }