This commit is contained in:
xaoxuu 2019-08-08 19:29:03 +08:00
parent 4cebb3fc72
commit 6596e6c971
3 changed files with 53 additions and 20 deletions

View File

@ -90,6 +90,35 @@ internal extension ProHUD.Configuration.Alert {
var loadForceQuitButton: (ProHUD.Alert) -> Void { var loadForceQuitButton: (ProHUD.Alert) -> Void {
return privLoadForceQuitButton return privLoadForceQuitButton
} }
var setupDefaultDuration: (ProHUD.Alert) -> Void {
return { (vc) in
//
if let t = vc.model.duration, t > 0 {
if vc.buttonEvents.count > 0 {
vc.duration(nil)
}
} else if vc.model.duration == nil && vc.model.scene != .loading {
//
vc.duration(2)
}
}
}
var reloadStack: (ProHUD.Alert) -> Void {
return { (vc) in
if vc.textStack.arrangedSubviews.count > 0 {
vc.contentStack.addArrangedSubview(vc.textStack)
} else {
vc.textStack.removeFromSuperview()
}
if vc.actionStack.arrangedSubviews.count > 0 {
vc.contentStack.addArrangedSubview(vc.actionStack)
} else {
vc.actionStack.removeFromSuperview()
}
}
}
} }
fileprivate var privLoadSubviews: (ProHUD.Alert) -> Void = { fileprivate var privLoadSubviews: (ProHUD.Alert) -> Void = {
@ -167,15 +196,8 @@ fileprivate var privReloadData: (ProHUD.Alert) -> Void = {
} }
vc.imageView = icon 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() vc.imageView?.layer.removeAllAnimations()
}
// text // text
if vc.model.title?.count ?? 0 > 0 || vc.model.message?.count ?? 0 > 0 { if vc.model.title?.count ?? 0 > 0 || vc.model.message?.count ?? 0 > 0 {
vc.contentStack.addArrangedSubview(vc.textStack) vc.contentStack.addArrangedSubview(vc.textStack)
@ -278,15 +300,8 @@ fileprivate var privReloadData: (ProHUD.Alert) -> Void = {
vc.view.layoutIfNeeded() vc.view.layoutIfNeeded()
} }
} }
switch vc.model.scene {
case .loading:
vc.duration(nil)
default:
vc.duration(2)
}
if vc.actionStack.arrangedSubviews.count > 0 {
vc.duration(nil)
}
} }
}() }()
@ -326,3 +341,6 @@ fileprivate var privLoadForceQuitButton: (ProHUD.Alert) -> Void = {
} }
} }
}() }()

View File

@ -189,7 +189,21 @@ public extension Alert {
@discardableResult func update(icon: UIImage?) -> Alert { @discardableResult func update(icon: UIImage?) -> Alert {
model.icon = icon model.icon = icon
cfg.alert.reloadData(self) cfg.alert.reloadData(self)
return self
}
@discardableResult func animate(rotate: Bool) -> Alert {
if rotate {
DispatchQueue.main.async {
let ani = CABasicAnimation(keyPath: "transform.rotation.z")
ani.toValue = M_PI*2.0
ani.duration = 2
ani.repeatCount = 10000
self.imageView?.layer.add(ani, forKey: "rotationAnimation")
}
} else {
imageView?.layer.removeAllAnimations() imageView?.layer.removeAllAnimations()
}
return self return self
} }
@ -297,6 +311,7 @@ fileprivate extension Alert {
// //
cfg.alert.loadSubviews(a) cfg.alert.loadSubviews(a)
cfg.alert.reloadData(a) cfg.alert.reloadData(a)
cfg.alert.setupDefaultDuration(a)
// 退 // 退
a.model.setupForceQuit(duration: cfg.alert.forceQuitTimer) { [weak self] in a.model.setupForceQuit(duration: cfg.alert.forceQuitTimer) { [weak self] in
if let aa = self, aa.actionStack.superview == nil { if let aa = self, aa.actionStack.superview == nil {

View File

@ -17,7 +17,7 @@ public class HUDController: UIViewController {
internal var disappearCallback: (() -> Void)? internal var disappearCallback: (() -> Void)?
/// ///
fileprivate var buttonEvents = [UIButton:() -> Void]() internal var buttonEvents = [UIButton:() -> Void]()
init() { init() {
super.init(nibName: nil, bundle: nil) super.init(nibName: nil, bundle: nil)