Files
real-e-party-iOS/YuMi/E-P/Common/EPProgressHUD.swift
edwinQQQ c0441f7853 refactor: 更新 EPProgressHUD 和 YUMIMacroUitls.h 以兼容 iOS 13+
主要变更:
1. 在 EPProgressHUD.swift 中引入 keyWindow 的兼容获取方法,替换原有的 UIApplication.shared.keyWindow 调用。
2. 在 YUMIMacroUitls.h 中添加状态栏高度和 keyWindow 的兼容宏定义,确保在 iOS 13+ 中正确获取相关窗口和状态栏信息。

此更新旨在提升代码的兼容性和稳定性,确保在新版本的 iOS 中正常运行。
2025-10-11 17:36:28 +08:00

63 lines
1.8 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// EPProgressHUD.swift
// YuMi
//
// Created by AI on 2025-10-11.
//
import UIKit
import Foundation
/// Loading MBProgressHUD
@objc class EPProgressHUD: NSObject {
private static var currentHUD: MBProgressHUD?
/// window iOS 13+
private static var keyWindow: UIWindow? {
if #available(iOS 13.0, *) {
return UIApplication.shared.connectedScenes
.compactMap { $0 as? UIWindowScene }
.flatMap { $0.windows }
.first { $0.isKeyWindow }
} else {
return UIApplication.shared.keyWindow
}
}
///
/// - Parameters:
/// - uploaded:
/// - total:
@objc static func showProgress(_ uploaded: Int, total: Int) {
DispatchQueue.main.async {
guard let window = keyWindow else { return }
if let hud = currentHUD {
// HUD
hud.label.text = "上传中 \(uploaded)/\(total)"
hud.progress = Float(uploaded) / Float(total)
} else {
// HUD
let hud = MBProgressHUD.showAdded(to: window, animated: true)
hud.mode = .determinateHorizontalBar
hud.label.text = "上传中 \(uploaded)/\(total)"
hud.progress = Float(uploaded) / Float(total)
hud.removeFromSuperViewOnHide = true
currentHUD = hud
}
}
}
/// HUD
@objc static func dismiss() {
DispatchQueue.main.async {
guard let hud = currentHUD else { return }
hud.hide(animated: true)
currentHUD = nil
}
}
}