diff --git a/ProHUD/Alert/AlertConfig.swift b/ProHUD/Alert/AlertConfig.swift index 80dd8f5..9a0e624 100644 --- a/ProHUD/Alert/AlertConfig.swift +++ b/ProHUD/Alert/AlertConfig.swift @@ -165,7 +165,15 @@ fileprivate var privReloadData: (ProHUD.Alert) -> Void = { } vc.imageView = icon } - + if vc.model.scene == .loading { + let ani = CABasicAnimation(keyPath: "transform.rotation.z") + ani.toValue = M_PI*2.0 + ani.duration = 2 + ani.repeatCount = 10000 + vc.imageView?.layer.add(ani, forKey: "rotationAnimation") + } else { + vc.imageView?.layer.removeAllAnimations() + } // text if vc.model.title?.count ?? 0 > 0 || vc.model.message?.count ?? 0 > 0 { vc.contentStack.addArrangedSubview(vc.textStack) @@ -263,6 +271,15 @@ fileprivate var privReloadData: (ProHUD.Alert) -> Void = { vc.view.layoutIfNeeded() } } + switch vc.model.scene { + case .loading: + vc.model.duration = nil + default: + vc.model.duration = 2 + } + if vc.actionStack.arrangedSubviews.count > 0 { + vc.model.duration = nil + } } }() diff --git a/ProHUD/Alert/AlertController.swift b/ProHUD/Alert/AlertController.swift index 9077194..369ec18 100644 --- a/ProHUD/Alert/AlertController.swift +++ b/ProHUD/Alert/AlertController.swift @@ -64,12 +64,6 @@ public extension ProHUD { model.title = title model.message = message model.icon = icon - switch scene { - case .loading: - model.duration = nil - default: - model.duration = 2 - } willLayoutSubviews() @@ -166,7 +160,7 @@ public extension ProHUD.Alert { model.scene = scene model.title = title model.message = message - cfg.alert.reloadData(self) + willLayoutSubviews() return self } @@ -175,6 +169,7 @@ public extension ProHUD.Alert { @discardableResult func update(icon: UIImage?) -> ProHUD.Alert { model.icon = icon cfg.alert.reloadData(self) + imageView?.layer.removeAllAnimations() return self } @@ -230,18 +225,20 @@ public extension ProHUD { /// 推入屏幕 /// - Parameter alert: 实例 @discardableResult func push(_ alert: Alert) -> Alert { - let window = getAlertWindow(alert) - window.makeKeyAndVisible() - window.resignKey() - window.addSubview(alert.view) - alert.view.transform = .init(scaleX: 1.2, y: 1.2) - alert.view.alpha = 0 - UIView.animateForAlertBuildIn { - alert.view.transform = .identity - alert.view.alpha = 1 - window.backgroundColor = window.backgroundColor?.withAlphaComponent(0.6) + if alerts.contains(alert) == false { + let window = getAlertWindow(alert) + window.makeKeyAndVisible() + window.resignKey() + window.addSubview(alert.view) + alert.view.transform = .init(scaleX: 1.2, y: 1.2) + alert.view.alpha = 0 + UIView.animateForAlertBuildIn { + alert.view.transform = .identity + alert.view.alpha = 1 + window.backgroundColor = window.backgroundColor?.withAlphaComponent(0.6) + } + alerts.append(alert) } - alerts.append(alert) updateAlertsLayout() // setup duration if let _ = alert.model.duration, alert.model.durationBlock == nil { @@ -436,7 +433,9 @@ fileprivate extension ProHUD { if alerts.count > 1 { for (i, a) in alerts.enumerated() { if a == alert { - alerts.remove(at: i) + if i < alerts.count { + alerts.remove(at: i) + } } } updateAlertsLayout() diff --git a/ProHUD/HUDController.swift b/ProHUD/HUDController.swift index cb858b1..c79d081 100644 --- a/ProHUD/HUDController.swift +++ b/ProHUD/HUDController.swift @@ -17,7 +17,7 @@ public class HUDController: UIViewController { internal var disappearCallback: (() -> Void)? /// 按钮事件 - internal var buttonEvents = [UIButton:() -> Void]() + fileprivate var buttonEvents = [UIButton:() -> Void]() init() { super.init(nibName: nil, bundle: nil) diff --git a/ProHUD/HUDView.swift b/ProHUD/HUDView.swift index dfc2676..f9aed8d 100644 --- a/ProHUD/HUDView.swift +++ b/ProHUD/HUDView.swift @@ -33,8 +33,11 @@ public extension ProHUD { if #available(iOS 13.0, *) { super.init(effect: UIBlurEffect(style: .systemMaterial)) - } else { + } else if #available(iOS 11.0, *) { super.init(effect: UIBlurEffect(style: .extraLight)) + } else { + super.init(effect: .none) + backgroundColor = .white } } diff --git a/ProHUD/ProHUD.xcassets/ProHUDLoading.imageset/ProHUDLoading@2x.png b/ProHUD/ProHUD.xcassets/ProHUDLoading.imageset/ProHUDLoading@2x.png index 6357f41..2f37d01 100644 Binary files a/ProHUD/ProHUD.xcassets/ProHUDLoading.imageset/ProHUDLoading@2x.png and b/ProHUD/ProHUD.xcassets/ProHUDLoading.imageset/ProHUDLoading@2x.png differ diff --git a/ProHUD/ProHUD.xcassets/ProHUDLoading.imageset/ProHUDLoading@3x.png b/ProHUD/ProHUD.xcassets/ProHUDLoading.imageset/ProHUDLoading@3x.png index 94d26bd..2e7513f 100644 Binary files a/ProHUD/ProHUD.xcassets/ProHUDLoading.imageset/ProHUDLoading@3x.png and b/ProHUD/ProHUD.xcassets/ProHUDLoading.imageset/ProHUDLoading@3x.png differ diff --git a/ProHUD/Toast/ToastConfig.swift b/ProHUD/Toast/ToastConfig.swift index afb99dc..033765e 100644 --- a/ProHUD/Toast/ToastConfig.swift +++ b/ProHUD/Toast/ToastConfig.swift @@ -123,5 +123,13 @@ fileprivate var privReloadData: (ProHUD.Toast) -> Void = { } vc.view.layoutIfNeeded() + switch vc.model.scene { + case .loading: + vc.model.duration = nil + default: + vc.model.duration = 3 + } + } + }() diff --git a/ProHUD/Toast/ToastController.swift b/ProHUD/Toast/ToastController.swift index b9b86f8..2143e45 100644 --- a/ProHUD/Toast/ToastController.swift +++ b/ProHUD/Toast/ToastController.swift @@ -71,12 +71,6 @@ public extension ProHUD { model.title = title model.message = message model.icon = icon - switch scene { - case .loading: - model.duration = nil - default: - model.duration = 2 - } // 布局 cfg.toast.loadSubviews(self)