PQStuckPointLoadingView.swift 3.0 KB

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