This commit is contained in:
xaoxuu 2019-08-02 14:50:42 +08:00
parent 082e976f5a
commit 1da5242844
4 changed files with 72 additions and 34 deletions

View File

@ -17,7 +17,7 @@ class ViewController: UIViewController {
ProHUD.configAlert { (alert) in ProHUD.configAlert { (alert) in
alert.minimizeTimeout = 1 alert.minimizeTimeout = 5
} }
@ -26,11 +26,23 @@ class ViewController: UIViewController {
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
ProHUD.show(alert: .delete, title: "确认删除", message: "此操作不可撤销").timeout(nil) let a = ProHUD.show(alert: .delete, title: "确认删除", message: "此操作不可撤销")
a.addAction(style: .destructive, title: "确认", action: { [weak a] in
a?.removeAction(index: 0).removeAction(index: 0)
a?.updateContent(scene: .loading, title: "正在删除", message: "请稍后片刻")
DispatchQueue.main.asyncAfter(deadline: .now()+1) {
a?.updateContent(scene: .success, title: "删除成功", message: "啊哈哈哈哈").timeout(2)
a?.addAction(style: .default, title: "我知道了", action: {
// a?.remove()
a?.removeAction(index: 0)
})
}
}).addAction(style: .cancel, title: "取消", action: nil)
ProHUD.show(alert: .loading, title: "确认删除", message: "此操作不可撤销").timeout(nil) //
// ProHUD.show(alert: .loading, title: "", message: "").timeout(nil)
ProHUD.show(alert: .confirm, title: "确认删除", message: "此操作不可撤销").timeout(3) //
// ProHUD.show(alert: .confirm, title: "", message: "").timeout(3)
// //
// a.addAction(style: .destructive, title: "") { [weak a] in // a.addAction(style: .destructive, title: "") { [weak a] in

View File

@ -60,24 +60,26 @@ public extension ProHUD.Configuration {
lazy var loadSubviews: (ProHUD.Alert, Alert) -> Void = { lazy var loadSubviews: (ProHUD.Alert, Alert) -> Void = {
return { (vc, config) in return { (vc, config) in
debugPrint(vc, "loadSubviews") debugPrint(vc, "loadSubviews")
vc.view.addSubview(vc.contentView) if vc.contentView.superview == nil {
vc.contentView.contentView.addSubview(vc.contentStack) vc.view.addSubview(vc.contentView)
vc.contentView.contentView.addSubview(vc.contentStack)
vc.contentStack.spacing = alertConfig.margin + alertConfig.padding
vc.contentStack.spacing = alertConfig.margin + alertConfig.padding
vc.contentView.layer.masksToBounds = true
vc.contentView.layer.cornerRadius = alertConfig.cornerRadius vc.contentView.layer.masksToBounds = true
vc.contentView.layer.cornerRadius = alertConfig.cornerRadius
vc.contentView.snp.makeConstraints { (mk) in
mk.center.equalToSuperview() vc.contentView.snp.makeConstraints { (mk) in
mk.width.lessThanOrEqualTo(CGFloat.minimum(UIScreen.main.bounds.width * 0.68, alertConfig.maxWidth)) mk.center.equalToSuperview()
} mk.width.lessThanOrEqualTo(CGFloat.minimum(UIScreen.main.bounds.width * 0.68, alertConfig.maxWidth))
vc.contentStack.snp.makeConstraints { (mk) in }
mk.centerX.equalToSuperview() vc.contentStack.snp.makeConstraints { (mk) in
mk.top.equalToSuperview().offset(alertConfig.padding) mk.centerX.equalToSuperview()
mk.bottom.equalToSuperview().offset(-alertConfig.padding) mk.top.equalToSuperview().offset(alertConfig.padding)
mk.leading.equalToSuperview().offset(alertConfig.padding) mk.bottom.equalToSuperview().offset(-alertConfig.padding)
mk.trailing.equalToSuperview().offset(-alertConfig.padding) mk.leading.equalToSuperview().offset(alertConfig.padding)
mk.trailing.equalToSuperview().offset(-alertConfig.padding)
}
} }
} }
@ -184,7 +186,15 @@ public extension ProHUD.Configuration {
vc.textStack.removeFromSuperview() vc.textStack.removeFromSuperview()
} }
if vc.actionStack.superview != nil { if vc.actionStack.superview != nil {
vc.contentStack.addArrangedSubview(vc.actionStack) if isFirstLayout {
vc.contentStack.addArrangedSubview(vc.actionStack)
} else {
vc.actionStack.transform = .init(scaleX: 1, y: 0.001)
UIView.animateForAlert {
vc.contentStack.addArrangedSubview(vc.actionStack)
vc.view.layoutIfNeeded()
}
}
// iPad // iPad
if isPortrait == false { if isPortrait == false {
vc.actionStack.axis = .horizontal vc.actionStack.axis = .horizontal
@ -195,17 +205,25 @@ public extension ProHUD.Configuration {
mk.width.greaterThanOrEqualTo(200) mk.width.greaterThanOrEqualTo(200)
mk.leading.trailing.equalToSuperview() mk.leading.trailing.equalToSuperview()
} }
} if isFirstLayout == false {
if isFirstLayout { UIView.animateForAlert {
vc.view.layoutIfNeeded() vc.actionStack.transform = .identity
vc.imageView?.transform = .init(scaleX: 0.75, y: 0.75) }
} else { }
} }
UIView.animateForAlert { if isFirstLayout {
vc.imageView?.transform = .identity
vc.view.layoutIfNeeded() vc.view.layoutIfNeeded()
vc.imageView?.transform = .init(scaleX: 0.75, y: 0.75)
UIView.animateForAlert {
vc.imageView?.transform = .identity
vc.view.layoutIfNeeded()
}
} else {
UIView.animateForAlert {
vc.view.layoutIfNeeded()
}
} }
} }
}() }()

View File

@ -127,7 +127,13 @@ public extension ProHUD {
if actionStack.superview == nil { if actionStack.superview == nil {
contentStack.addArrangedSubview(actionStack) contentStack.addArrangedSubview(actionStack)
} }
self.view.layoutIfNeeded()
button.transform = .init(scaleX: 1, y: 0.001)
actionStack.addArrangedSubview(button) actionStack.addArrangedSubview(button)
UIView.animateForAlert {
button.transform = .identity
self.view.layoutIfNeeded()
}
addTouchUpAction(for: button) { [weak self] in addTouchUpAction(for: button) { [weak self] in
action?() action?()
if button.tag == UIAlertAction.Style.cancel.rawValue { if button.tag == UIAlertAction.Style.cancel.rawValue {
@ -201,14 +207,16 @@ public extension ProHUD {
} else if index < self.actionStack.arrangedSubviews.count, let btn = self.actionStack.arrangedSubviews[index] as? UIButton { } else if index < self.actionStack.arrangedSubviews.count, let btn = self.actionStack.arrangedSubviews[index] as? UIButton {
btn.removeFromSuperview() btn.removeFromSuperview()
} }
if self.actionStack.arrangedSubviews.count == 0 {
self.actionStack.removeFromSuperview()
}
willLayoutSubviews()
UIView.animateForAlert { UIView.animateForAlert {
self.view.layoutIfNeeded() self.view.layoutIfNeeded()
} }
return self return self
} }
} }
} }

View File

@ -365,7 +365,7 @@ public extension ProHUD {
return shared.show(toast: toast, title: title, message: message, icon: icon) return shared.show(toast: toast, title: title, message: message, icon: icon)
} }
class func alert(identifier: String?) -> [Toast] { class func toast(identifier: String?) -> [Toast] {
return shared.toasts(identifier: identifier) return shared.toasts(identifier: identifier)
} }