// // 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(loadHidden), 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 loadShow() { isHidden = false loadingImage.displayGIF(data: nil, images: gifImages, repeatCount: .max, duration: duration ?? 2) } // 隐藏动画 @objc public func loadHidden() { isHidden = true loadingImage.removePlayGIF() } deinit { BFLog(message: "销毁加载中视图") } }