This commit is contained in:
xaoxuu 2019-08-08 09:53:54 +08:00
parent 34e7b0ffbb
commit c165d05de4
1 changed files with 30 additions and 67 deletions

View File

@ -8,6 +8,8 @@
import SnapKit
public typealias Guard = ProHUD.Guard
public extension ProHUD {
class Guard: HUDController {
@ -51,11 +53,10 @@ public extension ProHUD {
// MARK:
///
/// - Parameter scene:
/// - Parameter title:
/// - Parameter message:
/// - Parameter icon:
public convenience init(title: String? = nil, message: String? = nil) {
/// - Parameter actions:
public convenience init(title: String? = nil, message: String? = nil, actions: ((Guard) -> Void)? = nil) {
self.init()
view.tintColor = cfg.guard.tintColor
@ -65,11 +66,12 @@ public extension ProHUD {
if let _ = message {
add(message: message)
}
actions?(self)
cfg.guard.loadSubviews(self)
cfg.guard.reloadData(self)
cfg.guard.reloadStack(self)
//
//
let tap = UITapGestureRecognizer(target: self, action: #selector(privDidTapped(_:)))
view.addGestureRecognizer(tap)
@ -78,11 +80,12 @@ public extension ProHUD {
}
}
// MARK: -
public extension ProHUD.Guard {
public extension Guard {
// MARK:
@ -90,7 +93,6 @@ public extension ProHUD.Guard {
/// - Parameter viewController:
func push(to viewController: UIViewController? = nil) {
func f(_ vc: UIViewController) {
ProHUD.pop(guard: vc, animated: false)
view.layoutIfNeeded()
vc.addChild(self)
vc.view.addSubview(view)
@ -185,14 +187,14 @@ public extension ProHUD.Guard {
/// - Parameter style:
/// - Parameter title:
/// - Parameter action:
@discardableResult func add(action style: UIAlertAction.Style, title: String?, action: (() -> Void)?) -> UIButton {
@discardableResult func add(action style: UIAlertAction.Style, title: String?, handler: (() -> Void)?) -> UIButton {
let btn = Button.actionButton(title: title)
btn.titleLabel?.font = cfg.guard.buttonFont
actionStack.addArrangedSubview(btn)
cfg.guard.reloadStack(self)
btn.update(style: style)
addTouchUpAction(for: btn) { [weak self] in
action?()
handler?()
if btn.tag == UIAlertAction.Style.cancel.rawValue {
self?.pop()
}
@ -202,7 +204,7 @@ public extension ProHUD.Guard {
///
/// - Parameter index:
@discardableResult func remove(action index: Int...) -> ProHUD.Guard {
@discardableResult func remove(action index: Int...) -> Guard {
for (i, idx) in index.enumerated() {
privRemoveAction(index: idx-i)
}
@ -211,88 +213,49 @@ public extension ProHUD.Guard {
///
/// - Parameter callback:
@discardableResult func didDisappear(_ callback: (() -> Void)?) -> ProHUD.Guard {
@discardableResult func didDisappear(_ callback: (() -> Void)?) -> Guard {
disappearCallback = callback
return self
}
}
// MARK:
public extension ProHUD {
// MARK:
///
/// - Parameter alert:
@discardableResult func push(_ guard: Guard, to viewController: UIViewController? = nil) -> Guard {
`guard`.push(to: viewController)
return `guard`
}
public extension Guard {
///
/// - Parameter alert:
/// - Parameter title:
/// - Parameter message:
/// - Parameter icon:
@discardableResult func push(guard viewController: UIViewController? = nil, title: String? = nil, message: String? = nil, actions: ((Guard) -> Void)? = nil) -> Guard {
let g = Guard(title: title, message: message)
actions?(g)
g.view.layoutIfNeeded()
@discardableResult class func push(to viewController: UIViewController? = nil, actions: ((Guard) -> Void)? = nil) -> Guard {
let g = Guard(actions: actions)
g.push(to: viewController)
return g
}
///
/// - Parameter alert:
func pop(_ guard: Guard) {
`guard`.pop()
}
///
/// - Parameter alert:
func pop(guard from: UIViewController?, animated: Bool = true) {
if let vc = from {
for c in vc.children {
if c.isKind(of: Guard.self) {
if let cc = c as? Guard {
cc.pop(animated: animated)
///
/// - Parameter identifier:
class func guards(_ identifier: String?, from viewController: UIViewController? = nil) -> [Guard] {
var gg = [Guard]()
if let vc = viewController ?? cfg.rootViewController {
for child in vc.children {
if child.isKind(of: Guard.self) {
if let g = child as? Guard {
gg.append(g)
}
}
}
}
}
}
// 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, actions: ((Guard) -> Void)? = nil) -> Guard {
return shared.push(guard: viewController, title: title, message: message, actions: actions)
return gg
}
///
/// - Parameter alert:
class func pop(_ guard: Guard) {
shared.pop(`guard`)
}
///
/// - Parameter alert:
class func pop(guard from: UIViewController?, animated: Bool = true) {
shared.pop(guard: from, animated: animated)
`guard`.pop()
}
@ -302,7 +265,7 @@ public extension ProHUD {
// MARK: -
fileprivate extension ProHUD.Guard {
fileprivate extension Guard {
///
/// - Parameter sender:
@ -329,7 +292,7 @@ fileprivate extension ProHUD.Guard {
///
/// - Parameter index:
@discardableResult func privRemoveAction(index: Int) -> ProHUD.Guard {
@discardableResult func privRemoveAction(index: Int) -> Guard {
if index < 0 {
for view in self.actionStack.arrangedSubviews {
if let btn = view as? UIButton {