mirror of https://github.com/xaoxuu/ProHUD
update
This commit is contained in:
parent
082e976f5a
commit
1da5242844
|
@ -17,7 +17,7 @@ class ViewController: UIViewController {
|
|||
|
||||
|
||||
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?) {
|
||||
|
||||
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: .confirm, title: "确认删除", message: "此操作不可撤销").timeout(3)
|
||||
//
|
||||
// ProHUD.show(alert: .loading, title: "确认删除", message: "此操作不可撤销").timeout(nil)
|
||||
//
|
||||
// ProHUD.show(alert: .confirm, title: "确认删除", message: "此操作不可撤销").timeout(3)
|
||||
|
||||
//
|
||||
// a.addAction(style: .destructive, title: "删除") { [weak a] in
|
||||
|
|
|
@ -60,24 +60,26 @@ public extension ProHUD.Configuration {
|
|||
lazy var loadSubviews: (ProHUD.Alert, Alert) -> Void = {
|
||||
return { (vc, config) in
|
||||
debugPrint(vc, "loadSubviews")
|
||||
vc.view.addSubview(vc.contentView)
|
||||
vc.contentView.contentView.addSubview(vc.contentStack)
|
||||
|
||||
vc.contentStack.spacing = alertConfig.margin + alertConfig.padding
|
||||
|
||||
vc.contentView.layer.masksToBounds = true
|
||||
vc.contentView.layer.cornerRadius = alertConfig.cornerRadius
|
||||
|
||||
vc.contentView.snp.makeConstraints { (mk) in
|
||||
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()
|
||||
mk.top.equalToSuperview().offset(alertConfig.padding)
|
||||
mk.bottom.equalToSuperview().offset(-alertConfig.padding)
|
||||
mk.leading.equalToSuperview().offset(alertConfig.padding)
|
||||
mk.trailing.equalToSuperview().offset(-alertConfig.padding)
|
||||
if vc.contentView.superview == nil {
|
||||
vc.view.addSubview(vc.contentView)
|
||||
vc.contentView.contentView.addSubview(vc.contentStack)
|
||||
|
||||
vc.contentStack.spacing = alertConfig.margin + alertConfig.padding
|
||||
|
||||
vc.contentView.layer.masksToBounds = true
|
||||
vc.contentView.layer.cornerRadius = alertConfig.cornerRadius
|
||||
|
||||
vc.contentView.snp.makeConstraints { (mk) in
|
||||
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()
|
||||
mk.top.equalToSuperview().offset(alertConfig.padding)
|
||||
mk.bottom.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()
|
||||
}
|
||||
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
|
||||
if isPortrait == false {
|
||||
vc.actionStack.axis = .horizontal
|
||||
|
@ -195,17 +205,25 @@ public extension ProHUD.Configuration {
|
|||
mk.width.greaterThanOrEqualTo(200)
|
||||
mk.leading.trailing.equalToSuperview()
|
||||
}
|
||||
}
|
||||
if isFirstLayout {
|
||||
vc.view.layoutIfNeeded()
|
||||
vc.imageView?.transform = .init(scaleX: 0.75, y: 0.75)
|
||||
} else {
|
||||
if isFirstLayout == false {
|
||||
UIView.animateForAlert {
|
||||
vc.actionStack.transform = .identity
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
UIView.animateForAlert {
|
||||
vc.imageView?.transform = .identity
|
||||
if isFirstLayout {
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
|
|
@ -127,7 +127,13 @@ public extension ProHUD {
|
|||
if actionStack.superview == nil {
|
||||
contentStack.addArrangedSubview(actionStack)
|
||||
}
|
||||
self.view.layoutIfNeeded()
|
||||
button.transform = .init(scaleX: 1, y: 0.001)
|
||||
actionStack.addArrangedSubview(button)
|
||||
UIView.animateForAlert {
|
||||
button.transform = .identity
|
||||
self.view.layoutIfNeeded()
|
||||
}
|
||||
addTouchUpAction(for: button) { [weak self] in
|
||||
action?()
|
||||
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 {
|
||||
btn.removeFromSuperview()
|
||||
}
|
||||
if self.actionStack.arrangedSubviews.count == 0 {
|
||||
self.actionStack.removeFromSuperview()
|
||||
}
|
||||
willLayoutSubviews()
|
||||
UIView.animateForAlert {
|
||||
self.view.layoutIfNeeded()
|
||||
}
|
||||
return self
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -365,7 +365,7 @@ public extension ProHUD {
|
|||
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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue