mirror of https://github.com/xaoxuu/ProHUD
update
This commit is contained in:
parent
4cebb3fc72
commit
6596e6c971
|
@ -90,6 +90,35 @@ internal extension ProHUD.Configuration.Alert {
|
|||
var loadForceQuitButton: (ProHUD.Alert) -> Void {
|
||||
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 = {
|
||||
|
@ -167,15 +196,8 @@ 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()
|
||||
}
|
||||
vc.imageView?.layer.removeAllAnimations()
|
||||
|
||||
// text
|
||||
if vc.model.title?.count ?? 0 > 0 || vc.model.message?.count ?? 0 > 0 {
|
||||
vc.contentStack.addArrangedSubview(vc.textStack)
|
||||
|
@ -278,15 +300,8 @@ fileprivate var privReloadData: (ProHUD.Alert) -> Void = {
|
|||
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 = {
|
|||
}
|
||||
}
|
||||
}()
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -189,7 +189,21 @@ public extension Alert {
|
|||
@discardableResult func update(icon: UIImage?) -> Alert {
|
||||
model.icon = icon
|
||||
cfg.alert.reloadData(self)
|
||||
imageView?.layer.removeAllAnimations()
|
||||
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()
|
||||
}
|
||||
return self
|
||||
}
|
||||
|
||||
|
@ -297,6 +311,7 @@ fileprivate extension Alert {
|
|||
// 布局
|
||||
cfg.alert.loadSubviews(a)
|
||||
cfg.alert.reloadData(a)
|
||||
cfg.alert.setupDefaultDuration(a)
|
||||
// 强制退出按钮
|
||||
a.model.setupForceQuit(duration: cfg.alert.forceQuitTimer) { [weak self] in
|
||||
if let aa = self, aa.actionStack.superview == nil {
|
||||
|
|
|
@ -17,7 +17,7 @@ public class HUDController: UIViewController {
|
|||
internal var disappearCallback: (() -> Void)?
|
||||
|
||||
/// 按钮事件
|
||||
fileprivate var buttonEvents = [UIButton:() -> Void]()
|
||||
internal var buttonEvents = [UIButton:() -> Void]()
|
||||
|
||||
init() {
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
|
|
Loading…
Reference in New Issue