diff --git a/Example/Example/ViewController.swift b/Example/Example/ViewController.swift index e81bcd5..85a9b7f 100644 --- a/Example/Example/ViewController.swift +++ b/Example/Example/ViewController.swift @@ -33,8 +33,8 @@ class ViewController: UIViewController { // testUpdateAction() - testGuard() - +// testGuard() + fastGuard() } func testDelete() { @@ -100,6 +100,13 @@ class ViewController: UIViewController { + } + + func fastGuard() { + ProHUD.push(guard: self, title: "测试", message: "测试测试").add(action: .cancel, title: "OK", action: { + + }) + } override func touchesBegan(_ touches: Set, with event: UIEvent?) { diff --git a/ProHUD/Alert/AlertController.swift b/ProHUD/Alert/AlertController.swift index 13aa7c6..9077194 100644 --- a/ProHUD/Alert/AlertController.swift +++ b/ProHUD/Alert/AlertController.swift @@ -93,6 +93,7 @@ public extension ProHUD.Alert { /// 弹出屏幕 func pop() { + let hud = ProHUD.shared let window = hud.getAlertWindow(self) hud.removeItemFromArray(alert: self) UIView.animateForAlertBuildOut(animations: { @@ -260,19 +261,19 @@ public extension ProHUD { /// 获取指定的实例 /// - Parameter identifier: 指定实例的标识 - func alerts(identifier: String?) -> [Alert] { + func alert(_ identifier: String?) -> Alert? { var aa = [Alert]() for a in alerts { if a.identifier == identifier { aa.append(a) } } - return aa + return aa.last } /// 弹出屏幕 /// - Parameter alert: 实例 - func pop(alert: Alert) { + func pop(_ alert: Alert) { for a in alerts { if a == alert { a.pop() @@ -314,14 +315,14 @@ public extension ProHUD { /// 获取指定的实例 /// - Parameter identifier: 指定实例的标识 - class func alert(identifier: String?) -> [Alert] { - return shared.alerts(identifier: identifier) + class func alert(_ identifier: String?) -> Alert? { + return shared.alert(identifier) } /// 弹出屏幕 /// - Parameter alert: 实例 - class func pop(alert: Alert) { - shared.pop(alert: alert) + class func pop(_ alert: Alert) { + shared.pop(alert) } /// 弹出实例 diff --git a/ProHUD/Alert/AlertModel.swift b/ProHUD/Alert/AlertModel.swift index f1dfc79..32a83d3 100644 --- a/ProHUD/Alert/AlertModel.swift +++ b/ProHUD/Alert/AlertModel.swift @@ -29,27 +29,6 @@ public extension ProHUD.Alert { /// 错误场景 case error - public var backgroundColor: UIColor { - switch self { - case .success: - return UIColor.green - case .warning: - return UIColor.yellow - case .error: - return UIColor.red - default: - return .clear - } - } - - public var tintColor: UIColor { - switch self { - case .success, .error: - return .white - default: - return UIColor.darkGray - } - } } struct ViewModel { @@ -72,7 +51,7 @@ public extension ProHUD.Alert { /// 持续时间 internal var durationBlock: DispatchWorkItem? - /// 显示顶部按钮(最小化) + /// 强制退出按钮 internal var forceQuitTimerBlock: DispatchWorkItem? /// 强制退出代码 diff --git a/ProHUD/Guard/GuardController.swift b/ProHUD/Guard/GuardController.swift index 1d1b40a..c7a4394 100644 --- a/ProHUD/Guard/GuardController.swift +++ b/ProHUD/Guard/GuardController.swift @@ -42,8 +42,7 @@ public extension ProHUD { /// 是否是强制性的(点击空白处是否可以消失) public var force = false - private let tag = Int(23905340) - + /// 是否正在显示 private var displaying = false // MARK: 生命周期 @@ -102,6 +101,7 @@ public extension ProHUD.Guard { self.translateIn() } } + // FIXME: 如果传入vc为空,则push到根控制器 } @@ -187,6 +187,68 @@ public extension ProHUD.Guard { } +// MARK: 实例函数 + +public extension ProHUD { + + /// 推入屏幕 + /// - Parameter alert: 实例 + @discardableResult func push(_ guard: Guard, to viewController: UIViewController? = nil) -> Guard { + `guard`.push(to: viewController) + return `guard` + } + + /// 推入屏幕 + /// - Parameter alert: 场景 + /// - Parameter title: 标题 + /// - Parameter message: 正文 + /// - Parameter icon: 图标 + @discardableResult func push(guard viewController: UIViewController? = nil, title: String? = nil, message: String? = nil) -> Guard { + let g = Guard(title: title, message: message) + g.push(to: viewController) + return g + } + + /// 弹出屏幕 + /// - Parameter alert: 实例 + func pop(_ guard: Guard) { + `guard`.pop() + } + +} + +// MARK: 类函数 + +public extension ProHUD { + + /// 推入屏幕 + /// - Parameter alert: 实例 + @discardableResult class func push(_ guard: Guard, to viewController: UIViewController? = nil) -> Guard { + return shared.push(`guard`, to: viewController) + } + + /// 推入屏幕 + /// - Parameter alert: 场景 + /// - Parameter title: 标题 + /// - Parameter message: 正文 + /// - Parameter icon: 图标 + @discardableResult class func push(guard viewController: UIViewController? = nil, title: String? = nil, message: String? = nil) -> Guard { + return shared.push(guard: viewController, title: title, message: message) + } + + /// 弹出屏幕 + /// - Parameter alert: 实例 + class func pop(_ guard: Guard) { + shared.pop(`guard`) + } + + +} + + + +// MARK: - 私有 + fileprivate extension ProHUD.Guard { /// 点击事件 diff --git a/ProHUD/HUDView.swift b/ProHUD/HUDView.swift index 746c0a2..23e843b 100644 --- a/ProHUD/HUDView.swift +++ b/ProHUD/HUDView.swift @@ -35,7 +35,6 @@ public extension ProHUD { class StackContainer: UIStackView { - public override init(frame: CGRect) { super.init(frame: frame) spacing = cfg.alert.margin diff --git a/ProHUD/ProHUD.swift b/ProHUD/ProHUD.swift index bb18170..e7d5e90 100644 --- a/ProHUD/ProHUD.swift +++ b/ProHUD/ProHUD.swift @@ -8,8 +8,6 @@ import UIKit -internal let hud = ProHUD.shared - public class ProHUD { public static let shared = ProHUD() diff --git a/ProHUD/Toast/ToastController.swift b/ProHUD/Toast/ToastController.swift index 3e506ad..a3625ee 100644 --- a/ProHUD/Toast/ToastController.swift +++ b/ProHUD/Toast/ToastController.swift @@ -109,7 +109,7 @@ public extension ProHUD.Toast { /// 弹出屏幕 func pop() { - hud.removeItemFromArray(toast: self) + ProHUD.shared.removeItemFromArray(toast: self) UIView.animateForToast(animations: { let frame = self.window?.frame ?? .zero self.window?.transform = .init(translationX: 0, y: -200-frame.maxY) @@ -284,19 +284,19 @@ public extension ProHUD { /// 获取指定的toast /// - Parameter identifier: 标识 - func toasts(identifier: String?) -> [Toast] { + func toast(_ identifier: String?) -> Toast? { var tt = [Toast]() for t in toasts { if t.identifier == identifier { tt.append(t) } } - return tt + return tt.last } /// Toast弹出屏幕 /// - Parameter toast: 实例 - func pop(toast: Toast) { + func pop(_ toast: Toast) { for t in toasts { if t == toast { t.pop() @@ -338,14 +338,14 @@ public extension ProHUD { /// 获取指定的toast /// - Parameter identifier: 标识 - class func toast(identifier: String?) -> [Toast] { - return shared.toasts(identifier: identifier) + class func toast(_ identifier: String?) -> Toast? { + return shared.toast(identifier) } /// Toast弹出屏幕 /// - Parameter toast: 实例 - class func pop(toast: Toast) { - shared.pop(toast: toast) + class func pop(_ toast: Toast) { + shared.pop(toast) } /// Toast弹出屏幕