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()
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<UITouch>, with event: UIEvent?) {

View File

@ -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)
}
///

View File

@ -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?
/// 退

View File

@ -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: 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 {
///

View File

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

View File

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

View File

@ -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