PQStuckPointLoadingView.swift 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. import BFUIKit
  12. class PQStuckPointLoadingView: UIView {
  13. var cancelHandle: ((_ sender: UIButton) -> Void)?
  14. /// 同步进度显示
  15. lazy var loadingView: AnimatedImageView = {
  16. let videoLoadingView = AnimatedImageView()
  17. videoLoadingView.kf.setImage(with: URL(fileURLWithPath: (Bundle.current(moduleName: "BFStuckPointKit", isAssets: false)?.path(forResource: "stuckPoint_edit_loading", ofType: ".gif"))!))
  18. videoLoadingView.stopAnimating()
  19. return videoLoadingView
  20. }()
  21. lazy var navBarLeftBtn: UIButton = {
  22. let navBarLeftBtn = UIButton(type: .custom)
  23. navBarLeftBtn.frame = CGRect(x: 0, y: cDevice_iPhoneStatusBarHei, width: cDefaultMargin * 4, height: cDefaultMargin * 4)
  24. navBarLeftBtn.imageEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: -5, right: 0)
  25. navBarLeftBtn.imageEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: -5, right: 0)
  26. navBarLeftBtn.tintColor = BFConfig.shared.styleTitleColor
  27. navBarLeftBtn.setImage(imageInUIKit(by: "icon_detail_back")?.withRenderingMode(.alwaysTemplate), for: .normal)
  28. navBarLeftBtn.addTarget(self, action: #selector(cancelDownload(sender:)), for: .touchUpInside)
  29. return navBarLeftBtn
  30. }()
  31. override init(frame: CGRect) {
  32. super.init(frame: frame)
  33. backgroundColor = UIColor.init(red: 1, green: 1, blue: 1, alpha: 0.5)
  34. addSubViews()
  35. addLayout()
  36. loadingView.startAnimating()
  37. }
  38. required init?(coder _: NSCoder) {
  39. fatalError("init(coder:) has not been implemented")
  40. }
  41. override func layoutSubviews() {
  42. super.layoutSubviews()
  43. }
  44. func addSubViews() {
  45. addSubview(loadingView)
  46. addSubview(navBarLeftBtn)
  47. }
  48. func addLayout() {
  49. loadingView.snp.makeConstraints { make in
  50. // make.top.equalToSuperview().offset(cScreenWidth / 2.0 + cDevice_iPhoneStatusBarHei)
  51. make.centerX.equalTo(cScreenWidth / 2.0)
  52. make.centerY.equalTo(cScreenHeigth / 2.0)
  53. make.width.height.equalTo(cDefaultMargin * 10)
  54. }
  55. }
  56. func show() {
  57. if self.superview != nil {
  58. return
  59. }
  60. UIApplication.shared.keyWindow?.addSubview(self)
  61. loadingView.startAnimating()
  62. }
  63. /// 移除视图
  64. /// - Returns: <#description#>
  65. func removeMarskView() {
  66. loadingView.stopAnimating()
  67. if self.superview != nil {
  68. removeFromSuperview()
  69. }
  70. BFLog(message: "removeMarskViewremoveMarskViewremoveMarskViewremoveMarskView")
  71. }
  72. @objc func cancelDownload(sender: UIButton) {
  73. if cancelHandle != nil {
  74. cancelHandle!(sender)
  75. removeMarskView()
  76. }
  77. }
  78. deinit {
  79. BFLog(message: "销毁加载中视图1111111")
  80. }
  81. }