mirror of https://github.com/xaoxuu/ProHUD
update
This commit is contained in:
parent
ba1e0ecec0
commit
70a27f58f2
|
@ -17,31 +17,33 @@ class ViewController: UIViewController {
|
|||
|
||||
|
||||
ProHUD.config { (cfg) in
|
||||
// cfg.enableDebugPrint = false
|
||||
cfg.alert { (a) in
|
||||
a.forceQuitTimer = 2
|
||||
// a.iconSize = .init(width: 20, height: 80)
|
||||
}
|
||||
cfg.toast { (t) in
|
||||
// t.iconSize = .init(width: 300, height: 30)
|
||||
}
|
||||
// cfg.primaryLabelColor = .purple
|
||||
}
|
||||
|
||||
}
|
||||
func testToast() {
|
||||
let t = ProHUD.Toast(scene: .loading, title: "正在加载", message: "请稍候片刻")
|
||||
|
||||
let a = ProHUD.show(alert : .loading, title: "正在加载", message: "请稍候片刻")
|
||||
let a = ProHUD.push(alert : .loading, title: "正在加载", message: "请稍候片刻")
|
||||
a.didMinimize {
|
||||
hud.show(t)
|
||||
hud.push(t)
|
||||
}
|
||||
t.didTapped { [weak t] in
|
||||
t?.remove()
|
||||
let a2 = ProHUD.show(alert: .loading, title: "正在加载", message: "马上就要成功了")
|
||||
t?.pop()
|
||||
let a2 = ProHUD.push(alert: .loading, title: "正在加载", message: "马上就要成功了")
|
||||
DispatchQueue.main.asyncAfter(deadline: .now()+1) {
|
||||
let a3 = ProHUD.show(alert: .error, title: "加载失败", message: "点击充实")
|
||||
let a3 = ProHUD.push(alert: .error, title: "加载失败", message: "点击充实")
|
||||
a3.addAction(style: .default, title: "重新加载") { [weak a3] in
|
||||
a3?.updateContent(scene: .success, title: "加载成功", message: "马上就要成功了")
|
||||
a3?.updateAction(index: 0, style: .default, title: "OK", action: { [weak a2, a3] in
|
||||
a2?.remove()
|
||||
a3?.remove()
|
||||
a2?.pop()
|
||||
a3?.pop()
|
||||
}).removeAction(index: 1).removeAction(index: 1)
|
||||
}.addAction(style: .destructive, title: "终止", action: nil).addAction(style: .cancel, title: "取消", action: nil)
|
||||
|
||||
|
@ -51,7 +53,7 @@ class ViewController: UIViewController {
|
|||
}
|
||||
|
||||
func testDelete() {
|
||||
let a = ProHUD.show(alert: .delete, title: "确认删除", message: "此操作不可撤销")
|
||||
let a = ProHUD.push(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: "请稍后片刻")
|
||||
|
@ -64,8 +66,7 @@ class ViewController: UIViewController {
|
|||
|
||||
@IBAction func test(_ sender: UIButton) {
|
||||
let g = ProHUD.Guard(title: "请求权限", message: "请打开相机权限开关,否则无法进行测量。")
|
||||
// g.view.tintColor = .warning
|
||||
// g.loadBody(g.description)
|
||||
|
||||
g.loadTitle("呵呵")
|
||||
g.loadBody("请打开相机权限开关,否则无法进行测量。请打开相机权限开关,否则无法进行测量。")
|
||||
g.loadButton(style: .default, title: "测试弹窗", action: { [weak self] in
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
CD6CD87022F185A700F4FD4A /* ToastController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6CD86F22F185A700F4FD4A /* ToastController.swift */; };
|
||||
CD6CD87222F185AF00F4FD4A /* ToastConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6CD87122F185AF00F4FD4A /* ToastConfig.swift */; };
|
||||
CD6CD87522F185C200F4FD4A /* GuardController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6CD87422F185C200F4FD4A /* GuardController.swift */; };
|
||||
CD6CD87722F185C900F4FD4A /* GuardModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6CD87622F185C900F4FD4A /* GuardModel.swift */; };
|
||||
CD6CD87922F185D000F4FD4A /* GuardConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6CD87822F185D000F4FD4A /* GuardConfig.swift */; };
|
||||
CD6CD87B22F185D600F4FD4A /* GuardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6CD87A22F185D600F4FD4A /* GuardView.swift */; };
|
||||
CD95D22122E72C4C007559A3 /* ProHUD.h in Headers */ = {isa = PBXBuildFile; fileRef = CD95D21F22E72C4C007559A3 /* ProHUD.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
|
@ -38,7 +37,6 @@
|
|||
CD6CD86F22F185A700F4FD4A /* ToastController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToastController.swift; sourceTree = "<group>"; };
|
||||
CD6CD87122F185AF00F4FD4A /* ToastConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToastConfig.swift; sourceTree = "<group>"; };
|
||||
CD6CD87422F185C200F4FD4A /* GuardController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GuardController.swift; sourceTree = "<group>"; };
|
||||
CD6CD87622F185C900F4FD4A /* GuardModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GuardModel.swift; sourceTree = "<group>"; };
|
||||
CD6CD87822F185D000F4FD4A /* GuardConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GuardConfig.swift; sourceTree = "<group>"; };
|
||||
CD6CD87A22F185D600F4FD4A /* GuardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GuardView.swift; sourceTree = "<group>"; };
|
||||
CD95D21C22E72C4C007559A3 /* ProHUD.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ProHUD.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
|
@ -88,7 +86,6 @@
|
|||
isa = PBXGroup;
|
||||
children = (
|
||||
CD6CD87422F185C200F4FD4A /* GuardController.swift */,
|
||||
CD6CD87622F185C900F4FD4A /* GuardModel.swift */,
|
||||
CD6CD87822F185D000F4FD4A /* GuardConfig.swift */,
|
||||
CD6CD87A22F185D600F4FD4A /* GuardView.swift */,
|
||||
);
|
||||
|
@ -225,7 +222,6 @@
|
|||
CD16490B22EF09AB0077988C /* AlertModel.swift in Sources */,
|
||||
CD16491222EF0D900077988C /* HUDView.swift in Sources */,
|
||||
CDB6A07B22EEF06500AF6CF0 /* HUDController.swift in Sources */,
|
||||
CD6CD87722F185C900F4FD4A /* GuardModel.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
@ -154,11 +154,14 @@ fileprivate var privReloadData: (ProHUD.Alert) -> Void = {
|
|||
} else {
|
||||
let icon = UIImageView(image: img)
|
||||
vc.contentStack.addArrangedSubview(icon)
|
||||
icon.contentMode = .scaleAspectFit
|
||||
icon.snp.makeConstraints { (mk) in
|
||||
mk.top.greaterThanOrEqualTo(vc.contentView).offset(config.padding*2.25)
|
||||
mk.bottom.lessThanOrEqualTo(vc.contentView).offset(-config.padding*2.25)
|
||||
mk.leading.greaterThanOrEqualTo(vc.contentView).offset(config.padding*4)
|
||||
mk.trailing.lessThanOrEqualTo(vc.contentView).offset(-config.padding*4)
|
||||
mk.width.equalTo(config.iconSize.width)
|
||||
mk.height.equalTo(config.iconSize.height)
|
||||
}
|
||||
vc.imageView = icon
|
||||
}
|
||||
|
@ -295,7 +298,7 @@ fileprivate var privLoadForceQuitButton: (ProHUD.Alert) -> Void = {
|
|||
vc.addTouchUpAction(for: btn) { [weak vc] in
|
||||
debug("点击了隐藏")
|
||||
vc?.minimizeCallback?()
|
||||
vc?.remove()
|
||||
vc?.pop()
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
|
|
@ -79,7 +79,7 @@ public extension ProHUD {
|
|||
|
||||
|
||||
/// 移除
|
||||
public func remove() {
|
||||
public func pop() {
|
||||
let window = hud.getAlertWindow(self)
|
||||
hud.removeItemFromArray(alert: self)
|
||||
UIView.animateForAlertBuildOut(animations: {
|
||||
|
@ -222,7 +222,7 @@ fileprivate extension ProHUD.Alert {
|
|||
// 超时
|
||||
if let t = a.timeout, t > 0 {
|
||||
a.timeoutBlock = DispatchWorkItem(block: { [weak self] in
|
||||
self?.remove()
|
||||
self?.pop()
|
||||
})
|
||||
DispatchQueue.main.asyncAfter(deadline: .now()+t, execute: a.timeoutBlock!)
|
||||
} else {
|
||||
|
@ -257,7 +257,7 @@ fileprivate extension ProHUD.Alert {
|
|||
addTouchUpAction(for: button) { [weak self] in
|
||||
action?()
|
||||
if button.tag == UIAlertAction.Style.cancel.rawValue {
|
||||
self?.remove()
|
||||
self?.pop()
|
||||
}
|
||||
}
|
||||
willLayoutSubviews()
|
||||
|
@ -272,7 +272,7 @@ fileprivate extension ProHUD.Alert {
|
|||
public extension ProHUD {
|
||||
|
||||
@discardableResult
|
||||
func show(_ alert: Alert) -> Alert {
|
||||
func push(_ alert: Alert) -> Alert {
|
||||
let window = getAlertWindow(alert)
|
||||
window.makeKeyAndVisible()
|
||||
window.resignKey()
|
||||
|
@ -294,8 +294,8 @@ public extension ProHUD {
|
|||
}
|
||||
|
||||
@discardableResult
|
||||
func show(alert: Alert.Scene, title: String? = nil, message: String? = nil, icon: UIImage? = nil) -> Alert {
|
||||
return show(Alert(scene: alert, title: title, message: message, icon: icon))
|
||||
func push(alert: Alert.Scene, title: String? = nil, message: String? = nil, icon: UIImage? = nil) -> Alert {
|
||||
return push(Alert(scene: alert, title: title, message: message, icon: icon))
|
||||
}
|
||||
|
||||
func alerts(identifier: String?) -> [Alert] {
|
||||
|
@ -308,18 +308,18 @@ public extension ProHUD {
|
|||
return aa
|
||||
}
|
||||
|
||||
func remove(alert: Alert) {
|
||||
func pop(alert: Alert) {
|
||||
for a in alerts {
|
||||
if a == alert {
|
||||
a.remove()
|
||||
a.pop()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func remove(alert identifier: String?) {
|
||||
func pop(alert identifier: String?) {
|
||||
for a in alerts {
|
||||
if a.identifier == identifier {
|
||||
a.remove()
|
||||
a.pop()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -331,25 +331,25 @@ public extension ProHUD {
|
|||
public extension ProHUD {
|
||||
|
||||
@discardableResult
|
||||
class func show(_ alert: Alert) -> Alert {
|
||||
return shared.show(alert)
|
||||
class func push(_ alert: Alert) -> Alert {
|
||||
return shared.push(alert)
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
class func show(alert: Alert.Scene, title: String? = nil, message: String? = nil, icon: UIImage? = nil) -> Alert {
|
||||
return shared.show(alert: alert, title: title, message: message, icon: icon)
|
||||
class func push(alert: Alert.Scene, title: String? = nil, message: String? = nil, icon: UIImage? = nil) -> Alert {
|
||||
return shared.push(alert: alert, title: title, message: message, icon: icon)
|
||||
}
|
||||
|
||||
class func alert(identifier: String?) -> [Alert] {
|
||||
return shared.alerts(identifier: identifier)
|
||||
}
|
||||
|
||||
class func remove(alert: Alert) {
|
||||
shared.remove(alert: alert)
|
||||
class func pop(alert: Alert) {
|
||||
shared.pop(alert: alert)
|
||||
}
|
||||
|
||||
class func remove(alert identifier: String?) {
|
||||
shared.remove(alert: identifier)
|
||||
class func pop(alert identifier: String?) {
|
||||
shared.pop(alert: identifier)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -36,8 +36,7 @@ public extension ProHUD.Configuration {
|
|||
// MARK: 按钮样式
|
||||
/// 按钮字体
|
||||
public var buttonFont = UIFont.boldSystemFont(ofSize: 18)
|
||||
/// 按钮最大宽度(用于优化横屏或者iPad显示)
|
||||
// public var buttonMaxWidth = CGFloat(460)
|
||||
|
||||
/// 按钮圆角半径
|
||||
public var buttonCornerRadius = CGFloat(12)
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ public extension ProHUD {
|
|||
/// - Parameter icon: 图标
|
||||
public convenience init(title: String? = nil, message: String? = nil) {
|
||||
self.init()
|
||||
view = View()
|
||||
// view = View()
|
||||
view.tintColor = cfg.guard.tintColor
|
||||
if let _ = title {
|
||||
loadTitle(title)
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
//
|
||||
// GuardModel.swift
|
||||
// ProHUD
|
||||
//
|
||||
// Created by xaoxuu on 2019/7/31.
|
||||
// Copyright © 2019 Titan Studio. All rights reserved.
|
||||
//
|
||||
|
||||
public extension ProHUD.Guard {
|
||||
|
||||
struct ViewModel {
|
||||
|
||||
/// 标题
|
||||
public var title: String?
|
||||
|
||||
/// 正文
|
||||
public var message: String?
|
||||
|
||||
public init(title: String? = nil, message: String? = nil, icon: UIImage? = nil) {
|
||||
self.title = title
|
||||
self.message = message
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -9,35 +9,7 @@
|
|||
import UIKit
|
||||
|
||||
internal extension ProHUD.Guard {
|
||||
class View: UIView {
|
||||
|
||||
override func willMove(toSuperview newSuperview: UIView?) {
|
||||
if let sv = newSuperview {
|
||||
for v in sv.subviews {
|
||||
if let vv = v as? ProHUD.Guard.View {
|
||||
if vv.tag == self.tag {
|
||||
UIView.animate(withDuration: 0.38, delay: 0.1, options: .curveEaseIn, animations: {
|
||||
vv.alpha = 0
|
||||
}) { (done) in
|
||||
vv.removeFromSuperview()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// override func didMoveToSuperview() {
|
||||
// if let _ = superview {
|
||||
// snp.makeConstraints { (mk) in
|
||||
//// mk.left.right.bottom.equalToSuperview()
|
||||
// mk.edges.equalToSuperview()
|
||||
// }
|
||||
//// push(duration: duration)
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
class Button: UIButton {
|
||||
class func actionButton(title: String?) -> Button {
|
||||
let btn = Button(type: .system)
|
||||
|
|
|
@ -103,7 +103,7 @@ public extension ProHUD {
|
|||
|
||||
|
||||
/// 移除
|
||||
public func remove() {
|
||||
public func pop() {
|
||||
hud.removeItemFromArray(toast: self)
|
||||
UIView.animateForToast(animations: {
|
||||
let frame = self.window?.frame ?? .zero
|
||||
|
@ -147,7 +147,7 @@ public extension ProHUD {
|
|||
timeoutBlock?.cancel()
|
||||
if let t = timeout, t > 0 {
|
||||
timeoutBlock = DispatchWorkItem(block: { [weak self] in
|
||||
self?.remove()
|
||||
self?.pop()
|
||||
})
|
||||
DispatchQueue.main.asyncAfter(deadline: .now()+t, execute: timeoutBlock!)
|
||||
} else {
|
||||
|
@ -205,7 +205,7 @@ fileprivate extension ProHUD.Toast {
|
|||
let v = sender.velocity(in: sender.view)
|
||||
if removable == true && (((window?.frame.origin.y ?? 0) < 0 && v.y < 0) || v.y < -1200) {
|
||||
// 移除
|
||||
self.remove()
|
||||
self.pop()
|
||||
} else {
|
||||
UIView.animateForToast(animations: {
|
||||
self.window?.transform = .identity
|
||||
|
@ -223,7 +223,7 @@ fileprivate extension ProHUD.Toast {
|
|||
public extension ProHUD {
|
||||
|
||||
@discardableResult
|
||||
func show(_ toast: Toast) -> Toast {
|
||||
func push(_ toast: Toast) -> Toast {
|
||||
let config = cfg.toast
|
||||
let isNew: Bool
|
||||
if toast.window == nil {
|
||||
|
@ -276,8 +276,8 @@ public extension ProHUD {
|
|||
}
|
||||
|
||||
@discardableResult
|
||||
func show(toast: Toast.Scene, title: String? = nil, message: String? = nil, icon: UIImage? = nil) -> Toast {
|
||||
return show(Toast(scene: toast, title: title, message: message, icon: icon))
|
||||
func push(toast: Toast.Scene, title: String? = nil, message: String? = nil, icon: UIImage? = nil) -> Toast {
|
||||
return push(Toast(scene: toast, title: title, message: message, icon: icon))
|
||||
}
|
||||
|
||||
func toasts(identifier: String?) -> [Toast] {
|
||||
|
@ -290,18 +290,18 @@ public extension ProHUD {
|
|||
return tt
|
||||
}
|
||||
|
||||
func remove(toast: Toast) {
|
||||
func pop(toast: Toast) {
|
||||
for t in toasts {
|
||||
if t == toast {
|
||||
t.remove()
|
||||
t.pop()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func remove(toast identifier: String?) {
|
||||
func pop(toast identifier: String?) {
|
||||
for t in toasts {
|
||||
if t.identifier == identifier {
|
||||
t.remove()
|
||||
t.pop()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -313,25 +313,25 @@ public extension ProHUD {
|
|||
public extension ProHUD {
|
||||
|
||||
@discardableResult
|
||||
class func show(_ toast: Toast) -> Toast {
|
||||
return shared.show(toast)
|
||||
class func push(_ toast: Toast) -> Toast {
|
||||
return shared.push(toast)
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
class func show(toast: Toast.Scene, title: String? = nil, message: String? = nil, icon: UIImage? = nil) -> Toast {
|
||||
return shared.show(toast: toast, title: title, message: message, icon: icon)
|
||||
return shared.push(toast: toast, title: title, message: message, icon: icon)
|
||||
}
|
||||
|
||||
class func toast(identifier: String?) -> [Toast] {
|
||||
return shared.toasts(identifier: identifier)
|
||||
}
|
||||
|
||||
class func remove(toast: Toast) {
|
||||
shared.remove(toast: toast)
|
||||
class func pop(toast: Toast) {
|
||||
shared.pop(toast: toast)
|
||||
}
|
||||
|
||||
class func remove(toast identifier: String?) {
|
||||
shared.remove(toast: identifier)
|
||||
class func pop(toast identifier: String?) {
|
||||
shared.pop(toast: identifier)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,27 +29,6 @@ public extension ProHUD.Toast {
|
|||
/// 错误场景
|
||||
case error
|
||||
|
||||
// public var backgroundColor: UIColor {
|
||||
// switch self {
|
||||
// case .success:
|
||||
// return UIColor.green
|
||||
// case .warning:
|
||||
// return UIColor.yellow
|
||||
// case .error:
|
||||
// return UIColor.red
|
||||
// default:
|
||||
// return .clear
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public var tintColor: UIColor {
|
||||
// switch self {
|
||||
// case .success, .error:
|
||||
// return .white
|
||||
// default:
|
||||
// return UIColor.darkGray
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
struct ViewModel {
|
||||
|
|
Loading…
Reference in New Issue