123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- //
- // BFLoadingView.swift
- // BFRecordScreenKit
- //
- // Created by ak on 2022/2/17.
- //
- import BFCommonKit
- import BFUIKit
- import Kingfisher
- import UIKit
- class BFLoadingView: UIView {
- var cancelHandle: (() -> Void)?
-
- public lazy var loadingImage: UIImageView = {
- let loadingImage = UIImageView()
- loadingImage.image = imageInRecordScreenKit(by: "stuckPoint_edit_loading")
- return loadingImage
- }()
-
- //是否是下载音乐的模式,不发出回调不显示进度
- public var isDownloadMusic:Bool = false{
- didSet {
- if isDownloadMusic {
- titleL.text = ""
- }
- }
- }
- 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)
- }
- 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 - 150) / 2, y: loadingImage.frame.maxY + 10, width: 150, height: 22)
- }
- /// 显示动画
- public func loadShow() {
-
- isHidden = false
- loadingImage.layer.removeAllAnimations()
- loadingImage.isHidden = false
- // 1.创建动画
- let rotationAnim = CABasicAnimation(keyPath: "transform.rotation.z")
- // 2.设置动画的属性
- rotationAnim.fromValue = 0
- rotationAnim.toValue = Double.pi * 2
- rotationAnim.repeatCount = MAXFLOAT
- rotationAnim.duration = 1
- // 这个属性很重要 如果不设置当页面运行到后台再次进入该页面的时候 动画会停止
- rotationAnim.isRemovedOnCompletion = false
- // 3.将动画添加到layer中
- loadingImage.layer.add(rotationAnim, forKey: nil)
- }
-
- public func removeLoading(){
- isHidden = true
-
- loadingImage.layer.removeAllAnimations()
- loadingImage.isHidden = true
-
- }
- // 隐藏动画
- @objc public func loadHidden() {
- removeLoading()
- if cancelHandle != nil,!isDownloadMusic {
- cancelHandle!()
- }
-
-
- }
- deinit {
- BFLog(message: "销毁加载中视图")
- }
- }
|