This commit is contained in:
xaoxuu 2019-08-05 19:14:25 +08:00
parent 86b352bd44
commit d7d4e7d6ee
7 changed files with 90 additions and 44 deletions

View File

@ -33,8 +33,8 @@ class ViewController: UIViewController {
// testUpdateAction() // testUpdateAction()
testGuard() // testGuard()
fastGuard()
} }
func testDelete() { 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<UITouch>, with event: UIEvent?) { override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {

View File

@ -93,6 +93,7 @@ public extension ProHUD.Alert {
/// ///
func pop() { func pop() {
let hud = ProHUD.shared
let window = hud.getAlertWindow(self) let window = hud.getAlertWindow(self)
hud.removeItemFromArray(alert: self) hud.removeItemFromArray(alert: self)
UIView.animateForAlertBuildOut(animations: { UIView.animateForAlertBuildOut(animations: {
@ -260,19 +261,19 @@ public extension ProHUD {
/// ///
/// - Parameter identifier: /// - Parameter identifier:
func alerts(identifier: String?) -> [Alert] { func alert(_ identifier: String?) -> Alert? {
var aa = [Alert]() var aa = [Alert]()
for a in alerts { for a in alerts {
if a.identifier == identifier { if a.identifier == identifier {
aa.append(a) aa.append(a)
} }
} }
return aa return aa.last
} }
/// ///
/// - Parameter alert: /// - Parameter alert:
func pop(alert: Alert) { func pop(_ alert: Alert) {
for a in alerts { for a in alerts {
if a == alert { if a == alert {
a.pop() a.pop()
@ -314,14 +315,14 @@ public extension ProHUD {
/// ///
/// - Parameter identifier: /// - Parameter identifier:
class func alert(identifier: String?) -> [Alert] { class func alert(_ identifier: String?) -> Alert? {
return shared.alerts(identifier: identifier) return shared.alert(identifier)
} }
/// ///
/// - Parameter alert: /// - Parameter alert:
class func pop(alert: Alert) { class func pop(_ alert: Alert) {
shared.pop(alert: alert) shared.pop(alert)
} }
/// ///

View File

@ -29,27 +29,6 @@ public extension ProHUD.Alert {
/// ///
case error 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 { struct ViewModel {
@ -72,7 +51,7 @@ public extension ProHUD.Alert {
/// ///
internal var durationBlock: DispatchWorkItem? internal var durationBlock: DispatchWorkItem?
/// /// 退
internal var forceQuitTimerBlock: DispatchWorkItem? internal var forceQuitTimerBlock: DispatchWorkItem?
/// 退 /// 退

View File

@ -42,8 +42,7 @@ public extension ProHUD {
/// ///
public var force = false public var force = false
private let tag = Int(23905340) ///
private var displaying = false private var displaying = false
// MARK: // MARK:
@ -102,6 +101,7 @@ public extension ProHUD.Guard {
self.translateIn() self.translateIn()
} }
} }
// FIXME: vcpush
} }
@ -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 { fileprivate extension ProHUD.Guard {
/// ///

View File

@ -35,7 +35,6 @@ public extension ProHUD {
class StackContainer: UIStackView { class StackContainer: UIStackView {
public override init(frame: CGRect) { public override init(frame: CGRect) {
super.init(frame: frame) super.init(frame: frame)
spacing = cfg.alert.margin spacing = cfg.alert.margin

View File

@ -8,8 +8,6 @@
import UIKit import UIKit
internal let hud = ProHUD.shared
public class ProHUD { public class ProHUD {
public static let shared = ProHUD() public static let shared = ProHUD()

View File

@ -109,7 +109,7 @@ public extension ProHUD.Toast {
/// ///
func pop() { func pop() {
hud.removeItemFromArray(toast: self) ProHUD.shared.removeItemFromArray(toast: self)
UIView.animateForToast(animations: { UIView.animateForToast(animations: {
let frame = self.window?.frame ?? .zero let frame = self.window?.frame ?? .zero
self.window?.transform = .init(translationX: 0, y: -200-frame.maxY) self.window?.transform = .init(translationX: 0, y: -200-frame.maxY)
@ -284,19 +284,19 @@ public extension ProHUD {
/// toast /// toast
/// - Parameter identifier: /// - Parameter identifier:
func toasts(identifier: String?) -> [Toast] { func toast(_ identifier: String?) -> Toast? {
var tt = [Toast]() var tt = [Toast]()
for t in toasts { for t in toasts {
if t.identifier == identifier { if t.identifier == identifier {
tt.append(t) tt.append(t)
} }
} }
return tt return tt.last
} }
/// Toast /// Toast
/// - Parameter toast: /// - Parameter toast:
func pop(toast: Toast) { func pop(_ toast: Toast) {
for t in toasts { for t in toasts {
if t == toast { if t == toast {
t.pop() t.pop()
@ -338,14 +338,14 @@ public extension ProHUD {
/// toast /// toast
/// - Parameter identifier: /// - Parameter identifier:
class func toast(identifier: String?) -> [Toast] { class func toast(_ identifier: String?) -> Toast? {
return shared.toasts(identifier: identifier) return shared.toast(identifier)
} }
/// Toast /// Toast
/// - Parameter toast: /// - Parameter toast:
class func pop(toast: Toast) { class func pop(_ toast: Toast) {
shared.pop(toast: toast) shared.pop(toast)
} }
/// Toast /// Toast