Browse Source

loading ui 界面

jsonwang 3 years ago
parent
commit
753b0c1a5b
1 changed files with 98 additions and 0 deletions
  1. 98 0
      BFRecordScreenKit/Classes/RecordScreen/View/BFLoadingView.swift

+ 98 - 0
BFRecordScreenKit/Classes/RecordScreen/View/BFLoadingView.swift

@@ -0,0 +1,98 @@
+//
+//  BFLoadingView.swift
+//  BFRecordScreenKit
+//
+//  Created by ak on 2022/2/17.
+//
+
+import BFCommonKit
+import BFUIKit
+import Kingfisher
+import UIKit
+
+class BFLoadingView: UIView {
+    var cancelHandle: ((_ sender: UIButton) -> Void)?
+
+    // gif每一帧图
+    public var gifImages: [UIImage]?
+    // gif播放时长
+    public var duration: Double?
+
+    public lazy var loadingImage: UIImageView = {
+        let loadingImage = UIImageView()
+        loadingImage.tintColor = UIColor.hexColor(hexadecimal: BFConfig.shared.styleColor.rawValue)
+        return loadingImage
+    }()
+
+    lazy var closedBtn: UIButton = {
+        let closedBtn = UIButton(type: .custom)
+        closedBtn.frame = CGRect(x: 13, y: 43, width: cDefaultMargin * 3, height: cDefaultMargin * 3)
+        closedBtn.setImage(imageInRecordScreenKit(by: "LoadingClose"), for: .normal)
+        closedBtn.addTarget(self, action: #selector(removeView), for: .touchUpInside)
+        return closedBtn
+    }()
+
+    lazy var titleL: UILabel = {
+        let l = UILabel()
+        l.text = "变音中 10%"
+        l.textAlignment = .center
+        l.textColor = UIColor.hexColor(hexadecimal: "#389AFF")
+        l.font = UIFont.systemFont(ofSize: 16)
+
+        return l
+    }()
+
+    override init(frame: CGRect) {
+        super.init(frame: frame)
+        backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.7)
+        addSubview(loadingImage)
+        addSubview(closedBtn)
+        addSubview(titleL)
+
+        let data = try? Data(contentsOf: URL(fileURLWithPath: currentBundle()!.path(forResource: "stuckPoint_edit_loading", ofType: ".gif")!))
+        if data != nil {
+            PQPHAssetVideoParaseUtil.parasGIFImage(data: data!, isRenderingColor: UIColor.hexColor(hexadecimal: BFConfig.shared.styleColor.rawValue)) { [weak self] _, images, duration in
+                self?.gifImages = images
+                self?.duration = duration
+            }
+        }
+    }
+
+    required init?(coder _: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
+
+    override func layoutSubviews() {
+        super.layoutSubviews()
+        // 334 * 307
+        let imageW: CGFloat = 90
+        let imageH: CGFloat = 90
+        loadingImage.frame = CGRect(x: (frame.width - imageW) / 2, y: (frame.height - imageW) / 2, width: imageW, height: imageH)
+
+        titleL.frame = CGRect(x: (cScreenWidth - 88) / 2, y: loadingImage.frame.maxY + 10, width: 88, height: 22)
+    }
+
+    /// 开始加载
+    public func loading() {
+        if loadingImage.superview == nil {
+            addSubview(loadingImage)
+        }
+        isHidden = false
+        loadingImage.displayGIF(data: nil, images: gifImages, repeatCount: .max, duration: duration ?? 2)
+    }
+
+    /// 停止加载
+    public func endLoading() {
+        loadingImage.removePlayGIF()
+    }
+
+    @objc public func removeView() {
+        loadingImage.removePlayGIF()
+        loadingImage.removeFromSuperview()
+        removeFromSuperview()
+    }
+
+    deinit {
+        BFLog(message: "销毁加载中视图")
+    }
+}