mirror of https://github.com/xaoxuu/ProHUD
update
This commit is contained in:
parent
b8763cd45f
commit
082e976f5a
|
@ -380,7 +380,7 @@
|
||||||
CLANG_ENABLE_MODULES = YES;
|
CLANG_ENABLE_MODULES = YES;
|
||||||
CODE_SIGN_IDENTITY = "Apple Development";
|
CODE_SIGN_IDENTITY = "Apple Development";
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
DEVELOPMENT_TEAM = 34W5TB5KD2;
|
DEVELOPMENT_TEAM = WU2WFZ2B66;
|
||||||
INFOPLIST_FILE = Example/Info.plist;
|
INFOPLIST_FILE = Example/Info.plist;
|
||||||
LD_RUNPATH_SEARCH_PATHS = (
|
LD_RUNPATH_SEARCH_PATHS = (
|
||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
|
|
|
@ -18,6 +18,7 @@ class ViewController: UIViewController {
|
||||||
|
|
||||||
ProHUD.configAlert { (alert) in
|
ProHUD.configAlert { (alert) in
|
||||||
alert.minimizeTimeout = 1
|
alert.minimizeTimeout = 1
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,7 +26,12 @@ class ViewController: UIViewController {
|
||||||
|
|
||||||
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
|
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||||
|
|
||||||
// let a = ProHUD.show(alert: .delete, title: "确认删除", message: "此操作不可撤销")
|
ProHUD.show(alert: .delete, title: "确认删除", message: "此操作不可撤销").timeout(nil)
|
||||||
|
|
||||||
|
ProHUD.show(alert: .loading, title: "确认删除", message: "此操作不可撤销").timeout(nil)
|
||||||
|
|
||||||
|
ProHUD.show(alert: .confirm, title: "确认删除", message: "此操作不可撤销").timeout(3)
|
||||||
|
|
||||||
//
|
//
|
||||||
// a.addAction(style: .destructive, title: "删除") { [weak a] in
|
// a.addAction(style: .destructive, title: "删除") { [weak a] in
|
||||||
// a?.updateContent(scene: .success, title: "操作成功", message: "恭喜,您已经成功删除了xxx")
|
// a?.updateContent(scene: .success, title: "操作成功", message: "恭喜,您已经成功删除了xxx")
|
||||||
|
@ -45,36 +51,33 @@ class ViewController: UIViewController {
|
||||||
//
|
//
|
||||||
// }
|
// }
|
||||||
|
|
||||||
let t = ProHUD.Toast(scene: .loading, title: "正在加载", message: "请稍候片刻")
|
// let t = ProHUD.Toast(scene: .loading, title: "正在加载", message: "请稍候片刻")
|
||||||
|
//
|
||||||
let a = ProHUD.show(alert : .loading, title: "正在加载", message: "请稍候片刻")
|
// let a = ProHUD.show(alert : .loading, title: "正在加载", message: "请稍候片刻")
|
||||||
a.didMinimize {
|
// a.didMinimize {
|
||||||
hud.show(t)
|
// hud.show(t)
|
||||||
}
|
// }
|
||||||
t.didTapped { [weak t] in
|
// t.didTapped { [weak t] in
|
||||||
t?.remove()
|
// t?.remove()
|
||||||
let a2 = ProHUD.show(alert: .loading, title: "正在加载", message: "马上就要成功了")
|
// let a2 = ProHUD.show(alert: .loading, title: "正在加载", message: "马上就要成功了")
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now()+1) {
|
// DispatchQueue.main.asyncAfter(deadline: .now()+1) {
|
||||||
a2.updateContent(scene: .error, title: "加载失败", message: "点击充实")
|
// let a3 = ProHUD.show(alert: .error, title: "加载失败", message: "点击充实")
|
||||||
a2.addAction(style: .default, title: "重新加载") { [weak a2] in
|
// a3.addAction(style: .default, title: "重新加载") { [weak a3] in
|
||||||
a2?.updateContent(scene: .success, title: "加载成功", message: "马上就要成功了")
|
// a3?.updateContent(scene: .success, title: "加载成功", message: "马上就要成功了")
|
||||||
a2?.updateAction(index: 0, style: .default, title: "OK", action: { [weak a2] in
|
// a3?.updateAction(index: 0, style: .default, title: "OK", action: { [weak a2, a3] in
|
||||||
a2?.remove()
|
// a2?.remove()
|
||||||
}).removeAction(index: 1).removeAction(index: 1)
|
// a3?.remove()
|
||||||
}.addAction(style: .destructive, title: "终止", action: nil).addAction(style: .cancel, title: "取消", action: nil)
|
// }).removeAction(index: 1).removeAction(index: 1)
|
||||||
|
// }.addAction(style: .destructive, title: "终止", action: nil).addAction(style: .cancel, title: "取消", action: nil)
|
||||||
}
|
//
|
||||||
|
// }
|
||||||
}
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
// ProHUD.show(toast: .loading, title: "正在加载", message: "拉升的反馈老实交代分开就撒开了击快乐圣反馈老实交代分开就撒开了击快乐圣")
|
// ProHUD.show(toast: .loading, title: "正在加载", message: "拉升的反馈老实交代分开就撒开了击快乐圣反馈老实交代分开就撒开了击快乐圣")
|
||||||
// ProHUD.show(toast: .loading, title: "正在加载", message: "哈克里斯蒂娜疯狂拉升的反馈老实交代分开就撒开了击快乐圣诞哈克里斯蒂娜疯狂拉升的反馈老实交代分开就撒开了击快乐圣诞")
|
// ProHUD.show(toast: .loading, title: "正在加载", message: "哈克里斯蒂娜疯狂拉升的反馈老实交代分开就撒开了击快乐圣诞哈克里斯蒂娜疯狂拉升的反馈老实交代分开就撒开了击快乐圣诞")
|
||||||
|
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now()+1) {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,37 +11,54 @@ import SnapKit
|
||||||
|
|
||||||
public extension ProHUD.Configuration {
|
public extension ProHUD.Configuration {
|
||||||
struct Alert {
|
struct Alert {
|
||||||
|
// MARK: 卡片样式
|
||||||
/// 最大宽度(用于优化横屏或者iPad显示)
|
/// 最大宽度(用于优化横屏或者iPad显示)
|
||||||
public var maxWidth = CGFloat(400)
|
public var maxWidth = CGFloat(400)
|
||||||
/// 大标题字体
|
|
||||||
public var largeTitleFont = UIFont.boldSystemFont(ofSize: 22)
|
|
||||||
/// 标题字体
|
|
||||||
public var titleFont = UIFont.boldSystemFont(ofSize: 18)
|
|
||||||
/// 正文字体
|
|
||||||
public var bodyFont = UIFont.systemFont(ofSize: 17)
|
|
||||||
/// 按钮字体
|
|
||||||
public var buttonFont = UIFont.boldSystemFont(ofSize: 18)
|
|
||||||
/// 标题最多行数(0代表不限制)
|
|
||||||
public var titleMaxLines = Int(0)
|
|
||||||
/// 正文最多行数(0代表不限制)
|
|
||||||
public var bodyMaxLines = Int(0)
|
|
||||||
/// 圆角半径
|
/// 圆角半径
|
||||||
public var cornerRadius = CGFloat(16)
|
public var cornerRadius = CGFloat(16)
|
||||||
|
/// 余量:元素与元素之间的距离
|
||||||
public var margin = CGFloat(8)
|
public var margin = CGFloat(8)
|
||||||
|
/// 填充:元素内部控件距离元素边界的距离
|
||||||
public var padding = CGFloat(16)
|
public var padding = CGFloat(16)
|
||||||
|
|
||||||
|
// MARK: 图标样式
|
||||||
|
/// 图标、default按钮的颜色
|
||||||
|
public var tintColor: UIColor?
|
||||||
|
/// 图标尺寸
|
||||||
public var iconSize = CGSize(width: 48, height: 48)
|
public var iconSize = CGSize(width: 48, height: 48)
|
||||||
|
|
||||||
public var tintColor = UIColor.init(red: 3/255, green: 169/255, blue: 244/255, alpha: 1)
|
// MARK: 文本样式
|
||||||
|
/// 标题字体
|
||||||
|
public var titleFont = UIFont.boldSystemFont(ofSize: 22)
|
||||||
|
/// 标题颜色
|
||||||
|
public var titleColor = UIColor(white: 0.2, alpha: 1)
|
||||||
|
/// 标题最多行数
|
||||||
|
public var titleMaxLines = Int(1)
|
||||||
|
|
||||||
/// 多少秒后显示最小化的按钮
|
/// 加粗正文字体(如果只有标题或者只有正文,则显示这种字体)
|
||||||
|
public var boldTextFont = UIFont.boldSystemFont(ofSize: 18)
|
||||||
|
|
||||||
|
/// 正文字体
|
||||||
|
public var bodyFont = UIFont.systemFont(ofSize: 17)
|
||||||
|
/// 正文颜色
|
||||||
|
public var bodyColor = UIColor.darkGray
|
||||||
|
/// 正文最多行数
|
||||||
|
public var bodyMaxLines = Int(5)
|
||||||
|
|
||||||
|
// MARK: 按钮样式
|
||||||
|
/// 按钮字体
|
||||||
|
public var buttonFont = UIFont.boldSystemFont(ofSize: 18)
|
||||||
|
|
||||||
|
// MARK: 逻辑
|
||||||
|
/// 多少秒后显示强制退出的按钮(只有无按钮的弹窗才会出现)
|
||||||
public var minimizeTimeout = TimeInterval(10)
|
public var minimizeTimeout = TimeInterval(10)
|
||||||
|
/// 最小化按钮标题
|
||||||
|
public var minimizeTitle = String("隐藏窗口")
|
||||||
|
|
||||||
|
// MARK: 生命周期
|
||||||
/// 加载视图
|
/// 加载视图
|
||||||
lazy var loadSubviews: (ProHUD.Alert) -> Void = {
|
lazy var loadSubviews: (ProHUD.Alert, Alert) -> Void = {
|
||||||
return { (vc) in
|
return { (vc, config) in
|
||||||
debugPrint(vc, "loadSubviews")
|
debugPrint(vc, "loadSubviews")
|
||||||
vc.view.addSubview(vc.contentView)
|
vc.view.addSubview(vc.contentView)
|
||||||
vc.contentView.contentView.addSubview(vc.contentStack)
|
vc.contentView.contentView.addSubview(vc.contentStack)
|
||||||
|
@ -67,8 +84,8 @@ public extension ProHUD.Configuration {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
/// 更新视图
|
/// 更新视图
|
||||||
lazy var updateFrame: (ProHUD.Alert) -> Void = {
|
lazy var updateFrame: (ProHUD.Alert, Alert) -> Void = {
|
||||||
return { (vc) in
|
return { (vc, config) in
|
||||||
debugPrint(vc, "updateFrame")
|
debugPrint(vc, "updateFrame")
|
||||||
let isFirstLayout: Bool
|
let isFirstLayout: Bool
|
||||||
// 图标和文字至少有一个,如果都没有添加到视图中,说明是第一次layout
|
// 图标和文字至少有一个,如果都没有添加到视图中,说明是第一次layout
|
||||||
|
@ -101,10 +118,10 @@ public extension ProHUD.Configuration {
|
||||||
let icon = UIImageView(image: img)
|
let icon = UIImageView(image: img)
|
||||||
vc.contentStack.addArrangedSubview(icon)
|
vc.contentStack.addArrangedSubview(icon)
|
||||||
icon.snp.makeConstraints { (mk) in
|
icon.snp.makeConstraints { (mk) in
|
||||||
mk.top.greaterThanOrEqualTo(vc.contentView).offset(alertConfig.padding*2.25)
|
mk.top.greaterThanOrEqualTo(vc.contentView).offset(config.padding*2.25)
|
||||||
mk.bottom.lessThanOrEqualTo(vc.contentView).offset(-alertConfig.padding*2.25)
|
mk.bottom.lessThanOrEqualTo(vc.contentView).offset(-config.padding*2.25)
|
||||||
mk.leading.greaterThanOrEqualTo(vc.contentView).offset(alertConfig.padding*4)
|
mk.leading.greaterThanOrEqualTo(vc.contentView).offset(config.padding*4)
|
||||||
mk.trailing.lessThanOrEqualTo(vc.contentView).offset(-alertConfig.padding*4)
|
mk.trailing.lessThanOrEqualTo(vc.contentView).offset(-config.padding*4)
|
||||||
}
|
}
|
||||||
vc.imageView = icon
|
vc.imageView = icon
|
||||||
}
|
}
|
||||||
|
@ -113,10 +130,10 @@ public extension ProHUD.Configuration {
|
||||||
if vc.vm.title?.count ?? 0 > 0 || vc.vm.message?.count ?? 0 > 0 {
|
if vc.vm.title?.count ?? 0 > 0 || vc.vm.message?.count ?? 0 > 0 {
|
||||||
vc.contentStack.addArrangedSubview(vc.textStack)
|
vc.contentStack.addArrangedSubview(vc.textStack)
|
||||||
vc.textStack.snp.makeConstraints { (mk) in
|
vc.textStack.snp.makeConstraints { (mk) in
|
||||||
mk.top.greaterThanOrEqualTo(vc.contentView).offset(alertConfig.padding*1.75)
|
mk.top.greaterThanOrEqualTo(vc.contentView).offset(config.padding*1.75)
|
||||||
mk.bottom.lessThanOrEqualTo(vc.contentView).offset(-alertConfig.padding*1.75)
|
mk.bottom.lessThanOrEqualTo(vc.contentView).offset(-config.padding*1.75)
|
||||||
mk.leading.greaterThanOrEqualTo(vc.contentView).offset(alertConfig.padding*2)
|
mk.leading.greaterThanOrEqualTo(vc.contentView).offset(config.padding*2)
|
||||||
mk.trailing.lessThanOrEqualTo(vc.contentView).offset(-alertConfig.padding*2)
|
mk.trailing.lessThanOrEqualTo(vc.contentView).offset(-config.padding*2)
|
||||||
}
|
}
|
||||||
if vc.vm.title?.count ?? 0 > 0 {
|
if vc.vm.title?.count ?? 0 > 0 {
|
||||||
if let lb = vc.titleLabel {
|
if let lb = vc.titleLabel {
|
||||||
|
@ -124,18 +141,18 @@ public extension ProHUD.Configuration {
|
||||||
} else {
|
} else {
|
||||||
let title = UILabel()
|
let title = UILabel()
|
||||||
title.textAlignment = .center
|
title.textAlignment = .center
|
||||||
title.numberOfLines = alertConfig.titleMaxLines
|
title.numberOfLines = config.titleMaxLines
|
||||||
title.textColor = UIColor.init(white: 0.2, alpha: 1)
|
title.textColor = config.titleColor
|
||||||
title.text = vc.vm.title
|
title.text = vc.vm.title
|
||||||
vc.textStack.addArrangedSubview(title)
|
vc.textStack.addArrangedSubview(title)
|
||||||
vc.titleLabel = title
|
vc.titleLabel = title
|
||||||
}
|
}
|
||||||
if vc.vm.message?.count ?? 0 > 0 {
|
if vc.vm.message?.count ?? 0 > 0 {
|
||||||
// 有message
|
// 有message
|
||||||
vc.titleLabel?.font = alertConfig.largeTitleFont
|
vc.titleLabel?.font = config.titleFont
|
||||||
} else {
|
} else {
|
||||||
// 没有message
|
// 没有message
|
||||||
vc.titleLabel?.font = alertConfig.titleFont
|
vc.titleLabel?.font = config.boldTextFont
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
vc.titleLabel?.removeFromSuperview()
|
vc.titleLabel?.removeFromSuperview()
|
||||||
|
@ -146,19 +163,19 @@ public extension ProHUD.Configuration {
|
||||||
} else {
|
} else {
|
||||||
let body = UILabel()
|
let body = UILabel()
|
||||||
body.textAlignment = .center
|
body.textAlignment = .center
|
||||||
body.font = alertConfig.bodyFont
|
body.font = config.bodyFont
|
||||||
body.numberOfLines = alertConfig.bodyMaxLines
|
body.numberOfLines = config.bodyMaxLines
|
||||||
body.textColor = UIColor.darkGray
|
body.textColor = config.bodyColor
|
||||||
body.text = vc.vm.message
|
body.text = vc.vm.message
|
||||||
vc.textStack.addArrangedSubview(body)
|
vc.textStack.addArrangedSubview(body)
|
||||||
vc.messageLabel = body
|
vc.messageLabel = body
|
||||||
}
|
}
|
||||||
if vc.vm.title?.count ?? 0 > 0 {
|
if vc.vm.title?.count ?? 0 > 0 {
|
||||||
// 有title
|
// 有title
|
||||||
vc.messageLabel?.font = alertConfig.bodyFont
|
vc.messageLabel?.font = config.bodyFont
|
||||||
} else {
|
} else {
|
||||||
// 没有title
|
// 没有title
|
||||||
vc.messageLabel?.font = alertConfig.titleFont
|
vc.messageLabel?.font = config.boldTextFont
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
vc.messageLabel?.removeFromSuperview()
|
vc.messageLabel?.removeFromSuperview()
|
||||||
|
@ -186,22 +203,40 @@ public extension ProHUD.Configuration {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UIView.animateFastEaseOut(delay: 0, animations: {
|
UIView.animateForAlert {
|
||||||
vc.imageView?.transform = .identity
|
vc.imageView?.transform = .identity
|
||||||
vc.view.layoutIfNeeded()
|
vc.view.layoutIfNeeded()
|
||||||
}) { (done) in
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
/// 加载强制按钮
|
/// 加载强制按钮
|
||||||
lazy var showNavButtons: (ProHUD.Alert) -> Void = {
|
lazy var showNavButtons: (ProHUD.Alert, Alert) -> Void = {
|
||||||
return { (vc) in
|
return { (vc, config) in
|
||||||
debugPrint(vc, "showNavButtons")
|
debugPrint(vc, "showNavButtons")
|
||||||
let btn = UIButton.hideButton()
|
let btn = UIButton.minimizeButton()
|
||||||
vc.view.addSubview(btn)
|
let bg = ProHUD.BlurView()
|
||||||
|
bg.layer.masksToBounds = true
|
||||||
|
bg.layer.cornerRadius = config.cornerRadius
|
||||||
|
if let last = vc.view.subviews.last {
|
||||||
|
vc.view.insertSubview(bg, belowSubview: last)
|
||||||
|
} else {
|
||||||
|
vc.view.addSubview(bg)
|
||||||
|
}
|
||||||
|
bg.snp.makeConstraints { (mk) in
|
||||||
|
mk.leading.trailing.equalTo(vc.contentView)
|
||||||
|
mk.top.equalTo(vc.contentView.snp.bottom).offset(config.margin)
|
||||||
|
}
|
||||||
|
bg.contentView.addSubview(btn)
|
||||||
btn.snp.makeConstraints { (mk) in
|
btn.snp.makeConstraints { (mk) in
|
||||||
mk.leading.top.equalTo(vc.contentView).offset(alertConfig.margin/2)
|
mk.edges.equalToSuperview()
|
||||||
|
}
|
||||||
|
bg.alpha = 0
|
||||||
|
bg.layoutIfNeeded()
|
||||||
|
bg.transform = .init(translationX: 0, y: -2*(config.margin+bg.frame.size.height))
|
||||||
|
UIView.animateForAlert {
|
||||||
|
bg.alpha = 1
|
||||||
|
bg.transform = .identity
|
||||||
}
|
}
|
||||||
vc.addTouchUpAction(for: btn) { [weak vc] in
|
vc.addTouchUpAction(for: btn) { [weak vc] in
|
||||||
debugPrint("点击了隐藏")
|
debugPrint("点击了隐藏")
|
||||||
|
@ -213,13 +248,13 @@ public extension ProHUD.Configuration {
|
||||||
|
|
||||||
/// 加载视图
|
/// 加载视图
|
||||||
/// - Parameter callback: 回调代码
|
/// - Parameter callback: 回调代码
|
||||||
public mutating func loadSubviews(_ callback: @escaping (ProHUD.Alert) -> Void) {
|
public mutating func loadSubviews(_ callback: @escaping (ProHUD.Alert, Alert) -> Void) {
|
||||||
loadSubviews = callback
|
loadSubviews = callback
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 更新视图
|
/// 更新视图
|
||||||
/// - Parameter callback: 回调代码
|
/// - Parameter callback: 回调代码
|
||||||
public mutating func updateFrame(_ callback: @escaping (ProHUD.Alert) -> Void) {
|
public mutating func updateFrame(_ callback: @escaping (ProHUD.Alert, Alert) -> Void) {
|
||||||
updateFrame = callback
|
updateFrame = callback
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -82,15 +82,17 @@ public extension ProHUD {
|
||||||
public func remove() {
|
public func remove() {
|
||||||
let window = hud.getAlertWindow(self)
|
let window = hud.getAlertWindow(self)
|
||||||
hud.removeItemFromArray(alert: self)
|
hud.removeItemFromArray(alert: self)
|
||||||
animateOut { (done) in
|
UIView.animateForAlertBuildOut(animations: {
|
||||||
|
self.view.alpha = 0
|
||||||
|
self.view.transform = .init(scaleX: 1.08, y: 1.08)
|
||||||
|
}) { (done) in
|
||||||
self.view.removeFromSuperview()
|
self.view.removeFromSuperview()
|
||||||
self.removeFromParent()
|
self.removeFromParent()
|
||||||
}
|
}
|
||||||
// hide window
|
// hide window
|
||||||
let count = hud.alerts.count
|
let count = hud.alerts.count
|
||||||
if count == 0 && hud.alertWindow != nil {
|
if count == 0 && hud.alertWindow != nil {
|
||||||
UIView.animateFastEaseOut(delay: 0, animations: {
|
UIView.animateForAlertBuildOut(animations: {
|
||||||
self.view.transform = .init(scaleX: 1.05, y: 1.05)
|
|
||||||
window.backgroundColor = window.backgroundColor?.withAlphaComponent(0)
|
window.backgroundColor = window.backgroundColor?.withAlphaComponent(0)
|
||||||
}) { (done) in
|
}) { (done) in
|
||||||
hud.alertWindow = nil
|
hud.alertWindow = nil
|
||||||
|
@ -157,7 +159,7 @@ public extension ProHUD {
|
||||||
vm.message = message
|
vm.message = message
|
||||||
vm.scene = scene
|
vm.scene = scene
|
||||||
vm.icon = icon
|
vm.icon = icon
|
||||||
alertConfig.updateFrame(self)
|
alertConfig.updateFrame(self, alertConfig)
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,9 +185,8 @@ public extension ProHUD {
|
||||||
addTouchUpAction(for: btn, action: ac)
|
addTouchUpAction(for: btn, action: ac)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
UIView.animateFastEaseOut(delay: 0, animations: {
|
UIView.animateForAlert {
|
||||||
self.view.layoutIfNeeded()
|
self.view.layoutIfNeeded()
|
||||||
}) { (done) in
|
|
||||||
}
|
}
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
@ -200,9 +201,8 @@ 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()
|
||||||
}
|
}
|
||||||
UIView.animateFastEaseOut(delay: 0, animations: {
|
UIView.animateForAlert {
|
||||||
self.view.layoutIfNeeded()
|
self.view.layoutIfNeeded()
|
||||||
}) { (done) in
|
|
||||||
}
|
}
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
@ -221,8 +221,8 @@ fileprivate extension ProHUD.Alert {
|
||||||
willLayout = DispatchWorkItem(block: { [weak self] in
|
willLayout = DispatchWorkItem(block: { [weak self] in
|
||||||
if let a = self {
|
if let a = self {
|
||||||
// 布局
|
// 布局
|
||||||
alertConfig.loadSubviews(a)
|
alertConfig.loadSubviews(a, alertConfig)
|
||||||
alertConfig.updateFrame(a)
|
alertConfig.updateFrame(a, alertConfig)
|
||||||
// 超时
|
// 超时
|
||||||
if let t = a.timeout, t > 0 {
|
if let t = a.timeout, t > 0 {
|
||||||
a.timeoutBlock = DispatchWorkItem(block: { [weak self] in
|
a.timeoutBlock = DispatchWorkItem(block: { [weak self] in
|
||||||
|
@ -236,7 +236,7 @@ fileprivate extension ProHUD.Alert {
|
||||||
if alertConfig.minimizeTimeout > 0 && self?.actionStack.superview == nil {
|
if alertConfig.minimizeTimeout > 0 && self?.actionStack.superview == nil {
|
||||||
a.showNavButtonsBlock = DispatchWorkItem(block: { [weak self] in
|
a.showNavButtonsBlock = DispatchWorkItem(block: { [weak self] in
|
||||||
if let s = self {
|
if let s = self {
|
||||||
alertConfig.showNavButtons(s)
|
alertConfig.showNavButtons(s, alertConfig)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now()+alertConfig.minimizeTimeout, execute: a.showNavButtonsBlock!)
|
DispatchQueue.main.asyncAfter(deadline: .now()+alertConfig.minimizeTimeout, execute: a.showNavButtonsBlock!)
|
||||||
|
@ -260,15 +260,13 @@ public extension ProHUD {
|
||||||
window.makeKeyAndVisible()
|
window.makeKeyAndVisible()
|
||||||
window.resignKey()
|
window.resignKey()
|
||||||
window.addSubview(alert.view)
|
window.addSubview(alert.view)
|
||||||
UIView.animateFastEaseOut(delay: 0, animations: {
|
|
||||||
window.backgroundColor = window.backgroundColor?.withAlphaComponent(0.6)
|
|
||||||
})
|
|
||||||
alert.view.transform = .init(scaleX: 1.2, y: 1.2)
|
alert.view.transform = .init(scaleX: 1.2, y: 1.2)
|
||||||
alert.view.alpha = 0
|
alert.view.alpha = 0
|
||||||
UIView.animateFastEaseOut(delay: 0, animations: {
|
UIView.animateForAlertBuildIn {
|
||||||
alert.view.transform = .identity
|
alert.view.transform = .identity
|
||||||
alert.view.alpha = 1
|
alert.view.alpha = 1
|
||||||
})
|
window.backgroundColor = window.backgroundColor?.withAlphaComponent(0.6)
|
||||||
|
}
|
||||||
alerts.append(alert)
|
alerts.append(alert)
|
||||||
updateAlertsLayout()
|
updateAlertsLayout()
|
||||||
// setup timeout
|
// setup timeout
|
||||||
|
@ -345,7 +343,7 @@ internal extension ProHUD {
|
||||||
func updateAlertsLayout() {
|
func updateAlertsLayout() {
|
||||||
for (i, a) in alerts.reversed().enumerated() {
|
for (i, a) in alerts.reversed().enumerated() {
|
||||||
let scale = CGFloat(pow(0.7, CGFloat(i)))
|
let scale = CGFloat(pow(0.7, CGFloat(i)))
|
||||||
UIView.animate(withDuration: 2, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 0.5, options: [.allowUserInteraction, .curveEaseInOut], animations: {
|
UIView.animate(withDuration: 1.8, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 0.5, options: [.allowUserInteraction, .curveEaseInOut], animations: {
|
||||||
let y = -50 * CGFloat(i) * CGFloat(pow(0.8, CGFloat(i)))
|
let y = -50 * CGFloat(i) * CGFloat(pow(0.8, CGFloat(i)))
|
||||||
a.view.transform = CGAffineTransform.init(translationX: 0, y: y).scaledBy(x: scale, y: scale)
|
a.view.transform = CGAffineTransform.init(translationX: 0, y: y).scaledBy(x: scale, y: scale)
|
||||||
}) { (done) in
|
}) { (done) in
|
||||||
|
|
|
@ -14,22 +14,7 @@ public extension ProHUD.Alert {
|
||||||
}
|
}
|
||||||
|
|
||||||
extension UIButton {
|
extension UIButton {
|
||||||
class func hideButton() -> UIButton {
|
|
||||||
let btn = UIButton(type: .custom)
|
|
||||||
btn.contentEdgeInsets = .init(top: 8, left: 8, bottom: 8, right: 8)
|
|
||||||
btn.setImage(ProHUD.image(named: "ProHUDMinimize"), for: .normal)
|
|
||||||
btn.layer.shadowOpacity = 0.15
|
|
||||||
btn.layer.shadowOffset = .init(width: 0, height: 1.2)
|
|
||||||
btn.layer.shadowRadius = 1.2
|
|
||||||
btn.alpha = 0
|
|
||||||
btn.transform = .init(scaleX: 0.5, y: 0.5)
|
|
||||||
UIView.animateFastEaseOut(delay: 0, animations: {
|
|
||||||
btn.alpha = 1
|
|
||||||
btn.transform = .identity
|
|
||||||
}) { (done) in
|
|
||||||
}
|
|
||||||
return btn
|
|
||||||
}
|
|
||||||
class func actionButton(style: UIAlertAction.Style, title: String?) -> UIButton {
|
class func actionButton(style: UIAlertAction.Style, title: String?) -> UIButton {
|
||||||
let btn = UIButton(type: .system)
|
let btn = UIButton(type: .system)
|
||||||
btn.setTitle(title, for: .normal)
|
btn.setTitle(title, for: .normal)
|
||||||
|
@ -49,7 +34,7 @@ extension UIButton {
|
||||||
}
|
}
|
||||||
switch style {
|
switch style {
|
||||||
case .default:
|
case .default:
|
||||||
setTitleColor(tintColor, for: .normal)
|
setTitleColor(alertConfig.tintColor, for: .normal)
|
||||||
case .destructive:
|
case .destructive:
|
||||||
setTitleColor(.init(red: 244/255, green: 67/255, blue: 54/255, alpha: 1), for: .normal)
|
setTitleColor(.init(red: 244/255, green: 67/255, blue: 54/255, alpha: 1), for: .normal)
|
||||||
case .cancel:
|
case .cancel:
|
||||||
|
@ -60,4 +45,22 @@ extension UIButton {
|
||||||
tag = style.rawValue
|
tag = style.rawValue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class func minimizeButton() -> UIButton {
|
||||||
|
let btn = UIButton(type: .system)
|
||||||
|
// btn.contentEdgeInsets = .init(top: 8, left: 8, bottom: 8, right: 8)
|
||||||
|
let pd = alertConfig.padding/2
|
||||||
|
btn.contentEdgeInsets = .init(top: pd*1.5, left: pd*1.5, bottom: pd*1.5, right: pd*1.5)
|
||||||
|
// btn.imageEdgeInsets.left = pd*0.75
|
||||||
|
btn.imageEdgeInsets.right = pd*1.5
|
||||||
|
// btn.setImage(ProHUD.image(named: "ProHUDMinimize"), for: .normal)
|
||||||
|
// btn.layer.shadowOpacity = 0.15
|
||||||
|
// btn.layer.shadowOffset = .init(width: 0, height: 1.2)
|
||||||
|
// btn.layer.shadowRadius = 1.2
|
||||||
|
btn.setTitle(alertConfig.minimizeTitle, for: .normal)
|
||||||
|
btn.setTitleColor(UIColor(red:1.00, green:0.55, blue:0.21, alpha:1.00), for: .normal)
|
||||||
|
btn.titleLabel?.font = alertConfig.buttonFont
|
||||||
|
|
||||||
|
return btn
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import SnapKit
|
||||||
public extension ProHUD.Configuration {
|
public extension ProHUD.Configuration {
|
||||||
struct Guard {
|
struct Guard {
|
||||||
/// 最大宽度(用于优化横屏或者iPad显示)
|
/// 最大宽度(用于优化横屏或者iPad显示)
|
||||||
public var maxWidth = CGFloat(500)
|
public var maxWidth = CGFloat(556)
|
||||||
/// 标题字体
|
/// 标题字体
|
||||||
public var titleFont = UIFont.boldSystemFont(ofSize: 18)
|
public var titleFont = UIFont.boldSystemFont(ofSize: 18)
|
||||||
/// 正文字体
|
/// 正文字体
|
||||||
|
|
|
@ -48,13 +48,13 @@ public class HUDController: UIViewController {
|
||||||
|
|
||||||
internal extension HUDController {
|
internal extension HUDController {
|
||||||
|
|
||||||
func animateOut(completion: ((Bool) -> Void)? = nil) {
|
// func animateOut(completion: ((Bool) -> Void)? = nil) {
|
||||||
UIView.animateFastEaseOut(delay: 0, animations: {
|
// UIView.animateForAlertBuildOut(animations: {
|
||||||
self.view.alpha = 0
|
// self.view.alpha = 0
|
||||||
}) { (done) in
|
// }) { (done) in
|
||||||
completion?(done)
|
// completion?(done)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
func addTouchUpAction(for button: UIButton, action: @escaping () -> Void) {
|
func addTouchUpAction(for button: UIButton, action: @escaping () -> Void) {
|
||||||
button.addTarget(self, action: #selector(didTappedButton(_:)), for: .touchUpInside)
|
button.addTarget(self, action: #selector(didTappedButton(_:)), for: .touchUpInside)
|
||||||
|
|
|
@ -74,12 +74,18 @@ internal extension UIView {
|
||||||
animate(withDuration: duration, delay: delay, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: [.allowUserInteraction, .curveEaseOut], animations: animations, completion: completion)
|
animate(withDuration: duration, delay: delay, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: [.allowUserInteraction, .curveEaseOut], animations: animations, completion: completion)
|
||||||
}
|
}
|
||||||
|
|
||||||
class func animateFastEaseOut(delay: TimeInterval = 0, animations: @escaping () -> Void, completion: ((Bool) -> Void)? = nil) {
|
class func animateForAlertBuildIn(animations: @escaping () -> Void) {
|
||||||
animateEaseOut(duration: 0.5, delay: delay, animations: animations, completion: completion)
|
animateEaseOut(duration: 0.8, delay: 0, animations: animations, completion: nil)
|
||||||
|
}
|
||||||
|
class func animateForAlertBuildOut(animations: @escaping () -> Void, completion: ((Bool) -> Void)? = nil) {
|
||||||
|
animateEaseOut(duration: 0.38, delay: 0, animations: animations, completion: completion)
|
||||||
|
}
|
||||||
|
class func animateForAlert(animations: @escaping () -> Void) {
|
||||||
|
animateEaseOut(duration: 1, delay: 0, animations: animations, completion: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
class func animateSlowEaseOut(delay: TimeInterval = 0, animations: @escaping () -> Void, completion: ((Bool) -> Void)? = nil) {
|
class func animateForAlert(animations: @escaping () -> Void, completion: ((Bool) -> Void)? = nil) {
|
||||||
animateEaseOut(duration: 2, delay: delay, animations: animations, completion: completion)
|
animateEaseOut(duration: 1, delay: 0, animations: animations, completion: completion)
|
||||||
}
|
}
|
||||||
|
|
||||||
class func animateForToast(animations: @escaping () -> Void) {
|
class func animateForToast(animations: @escaping () -> Void) {
|
||||||
|
|
|
@ -18,5 +18,8 @@
|
||||||
"info" : {
|
"info" : {
|
||||||
"version" : 1,
|
"version" : 1,
|
||||||
"author" : "xcode"
|
"author" : "xcode"
|
||||||
|
},
|
||||||
|
"properties" : {
|
||||||
|
"template-rendering-intent" : "original"
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -11,7 +11,7 @@ import SnapKit
|
||||||
public extension ProHUD.Configuration {
|
public extension ProHUD.Configuration {
|
||||||
struct Toast {
|
struct Toast {
|
||||||
/// 最大宽度(用于优化横屏或者iPad显示)
|
/// 最大宽度(用于优化横屏或者iPad显示)
|
||||||
public var maxWidth = CGFloat(500)
|
public var maxWidth = CGFloat(556)
|
||||||
/// 标题字体
|
/// 标题字体
|
||||||
public var titleFont = UIFont.boldSystemFont(ofSize: 18)
|
public var titleFont = UIFont.boldSystemFont(ofSize: 18)
|
||||||
/// 正文字体
|
/// 正文字体
|
||||||
|
|
Loading…
Reference in New Issue