diff --git a/PHDemo/PHDemo/AlertVC.swift b/PHDemo/PHDemo/AlertVC.swift index 36efc2f..4c252f5 100644 --- a/PHDemo/PHDemo/AlertVC.swift +++ b/PHDemo/PHDemo/AlertVC.swift @@ -91,20 +91,34 @@ class AlertVC: ListVC { } } list.add(title: "图标 + 文字 + 按钮") { section in - section.add(title: "图标 + 一段文字 + 自定义浅色按钮") { - Alert(.confirm) { alert in - alert.vm.title = "自定义浅色按钮" + section.add(title: "操作成功") { + Alert(.success(3).title("操作成功").message("这条消息将在3s后消失")).push() + } + section.add(title: "操作失败") { + Alert { alert in + alert.vm = .error.title("操作失败").message("请稍后重试") + alert.add(action: "取消", style: .gray) + alert.add(action: "重试") + } + } + section.add(title: "警告") { + Alert(.warning.message("电量不足,请立即充电")) { alert in + let btn = alert.add(action: "我知道了", style: .filled(color: UIColor.systemYellow)) + btn.setTitleColor(.black, for: .normal) + } + } + section.add(title: "确认选择") { + Alert(.confirm.title("请选择颜色")) { alert in alert.add(action: "红色", style: .light(color: .systemRed)) alert.add(action: "蓝色", style: .light(color: .systemBlue)) } } - section.add(title: "图标 + 标题 + 正文 + 自定义深色按钮") { - Alert(.note) { alert in - alert.vm.title = "自定义深色按钮" - alert.vm.message = "这是一段正文,长度超出最大宽度时会自动换行" - alert.add(action: "橙色", style: .filled(color: .systemOrange)) - alert.add(action: "粉色", style: .filled(color: .systemPink)) - alert.add(action: "默认灰色", style: .gray) + section.add(title: "确认删除") { + Alert(.delete) { alert in + alert.vm.title = "确认删除" + alert.vm.message = "此操作无法撤销" + alert.add(action: "取消", style: .gray) + alert.add(action: "删除", style: .destructive) } } } @@ -213,9 +227,13 @@ class AlertVC: ListVC { let vc = UIViewController() vc.title = "页面" vc.view.backgroundColor = .systemYellow - let alert = Alert(.loading.title("正在加载").message("这个弹窗被放在指定的容器中")) + let alert = Alert(.loading.title("正在加载").message("这个弹窗被放在指定容器中")) + alert.add(action: "返回上一页") { alert in + vc.dismiss(animated: true) + } alert.config.enableShadow = false self?.present(vc, animated: true) + vc.addChild(alert) vc.view.addSubview(alert.view) alert.view.snp.makeConstraints { make in make.edges.equalToSuperview() diff --git a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.trash.imageset/Contents.json b/PHDemo/PHDemo/Assets.xcassets/demo.message.imageset/Contents.json similarity index 76% rename from Sources/ProHUD/Resources/ProHUD.xcassets/prohud.trash.imageset/Contents.json rename to PHDemo/PHDemo/Assets.xcassets/demo.message.imageset/Contents.json index 551989a..801eb8e 100644 --- a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.trash.imageset/Contents.json +++ b/PHDemo/PHDemo/Assets.xcassets/demo.message.imageset/Contents.json @@ -5,12 +5,12 @@ "scale" : "1x" }, { - "filename" : "prohud.trash@2x.png", + "filename" : "demo.message@2x.png", "idiom" : "universal", "scale" : "2x" }, { - "filename" : "prohud.trash@3x.png", + "filename" : "demo.message@3x.png", "idiom" : "universal", "scale" : "3x" } diff --git a/PHDemo/PHDemo/Assets.xcassets/demo.message.imageset/demo.message@2x.png b/PHDemo/PHDemo/Assets.xcassets/demo.message.imageset/demo.message@2x.png new file mode 100644 index 0000000..7bf8c1b Binary files /dev/null and b/PHDemo/PHDemo/Assets.xcassets/demo.message.imageset/demo.message@2x.png differ diff --git a/PHDemo/PHDemo/Assets.xcassets/demo.message.imageset/demo.message@3x.png b/PHDemo/PHDemo/Assets.xcassets/demo.message.imageset/demo.message@3x.png new file mode 100644 index 0000000..7436293 Binary files /dev/null and b/PHDemo/PHDemo/Assets.xcassets/demo.message.imageset/demo.message@3x.png differ diff --git a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.note.imageset/Contents.json b/PHDemo/PHDemo/Assets.xcassets/demo.note.imageset/Contents.json similarity index 76% rename from Sources/ProHUD/Resources/ProHUD.xcassets/prohud.note.imageset/Contents.json rename to PHDemo/PHDemo/Assets.xcassets/demo.note.imageset/Contents.json index 91ca9d0..f0ae711 100644 --- a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.note.imageset/Contents.json +++ b/PHDemo/PHDemo/Assets.xcassets/demo.note.imageset/Contents.json @@ -5,12 +5,12 @@ "scale" : "1x" }, { - "filename" : "prohud.note@2x.png", + "filename" : "demo.note@2x.png", "idiom" : "universal", "scale" : "2x" }, { - "filename" : "prohud.note@3x.png", + "filename" : "demo.note@3x.png", "idiom" : "universal", "scale" : "3x" } diff --git a/PHDemo/PHDemo/Assets.xcassets/demo.note.imageset/demo.note@2x.png b/PHDemo/PHDemo/Assets.xcassets/demo.note.imageset/demo.note@2x.png new file mode 100644 index 0000000..ee6a901 Binary files /dev/null and b/PHDemo/PHDemo/Assets.xcassets/demo.note.imageset/demo.note@2x.png differ diff --git a/PHDemo/PHDemo/Assets.xcassets/demo.note.imageset/demo.note@3x.png b/PHDemo/PHDemo/Assets.xcassets/demo.note.imageset/demo.note@3x.png new file mode 100644 index 0000000..4cf439d Binary files /dev/null and b/PHDemo/PHDemo/Assets.xcassets/demo.note.imageset/demo.note@3x.png differ diff --git a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.message.imageset/Contents.json b/PHDemo/PHDemo/Assets.xcassets/demo.questionmark.imageset/Contents.json similarity index 74% rename from Sources/ProHUD/Resources/ProHUD.xcassets/prohud.message.imageset/Contents.json rename to PHDemo/PHDemo/Assets.xcassets/demo.questionmark.imageset/Contents.json index 0219061..6095927 100644 --- a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.message.imageset/Contents.json +++ b/PHDemo/PHDemo/Assets.xcassets/demo.questionmark.imageset/Contents.json @@ -5,12 +5,12 @@ "scale" : "1x" }, { - "filename" : "prohud.message@2x.png", + "filename" : "demo.questionmark@2x.png", "idiom" : "universal", "scale" : "2x" }, { - "filename" : "prohud.message@3x.png", + "filename" : "demo.questionmark@3x.png", "idiom" : "universal", "scale" : "3x" } diff --git a/PHDemo/PHDemo/Assets.xcassets/demo.questionmark.imageset/demo.questionmark@2x.png b/PHDemo/PHDemo/Assets.xcassets/demo.questionmark.imageset/demo.questionmark@2x.png new file mode 100644 index 0000000..5251a23 Binary files /dev/null and b/PHDemo/PHDemo/Assets.xcassets/demo.questionmark.imageset/demo.questionmark@2x.png differ diff --git a/PHDemo/PHDemo/Assets.xcassets/demo.questionmark.imageset/demo.questionmark@3x.png b/PHDemo/PHDemo/Assets.xcassets/demo.questionmark.imageset/demo.questionmark@3x.png new file mode 100644 index 0000000..5a8a69e Binary files /dev/null and b/PHDemo/PHDemo/Assets.xcassets/demo.questionmark.imageset/demo.questionmark@3x.png differ diff --git a/PHDemo/PHDemo/Assets.xcassets/prohud.trash.imageset/Contents.json b/PHDemo/PHDemo/Assets.xcassets/demo.trash.imageset/Contents.json similarity index 76% rename from PHDemo/PHDemo/Assets.xcassets/prohud.trash.imageset/Contents.json rename to PHDemo/PHDemo/Assets.xcassets/demo.trash.imageset/Contents.json index 551989a..acbfc82 100644 --- a/PHDemo/PHDemo/Assets.xcassets/prohud.trash.imageset/Contents.json +++ b/PHDemo/PHDemo/Assets.xcassets/demo.trash.imageset/Contents.json @@ -5,12 +5,12 @@ "scale" : "1x" }, { - "filename" : "prohud.trash@2x.png", + "filename" : "demo.trash@2x.png", "idiom" : "universal", "scale" : "2x" }, { - "filename" : "prohud.trash@3x.png", + "filename" : "demo.trash@3x.png", "idiom" : "universal", "scale" : "3x" } diff --git a/PHDemo/PHDemo/Assets.xcassets/demo.trash.imageset/demo.trash@2x.png b/PHDemo/PHDemo/Assets.xcassets/demo.trash.imageset/demo.trash@2x.png new file mode 100644 index 0000000..73802ec Binary files /dev/null and b/PHDemo/PHDemo/Assets.xcassets/demo.trash.imageset/demo.trash@2x.png differ diff --git a/PHDemo/PHDemo/Assets.xcassets/demo.trash.imageset/demo.trash@3x.png b/PHDemo/PHDemo/Assets.xcassets/demo.trash.imageset/demo.trash@3x.png new file mode 100644 index 0000000..571bd08 Binary files /dev/null and b/PHDemo/PHDemo/Assets.xcassets/demo.trash.imageset/demo.trash@3x.png differ diff --git a/PHDemo/PHDemo/Assets.xcassets/prohud.rainbow.circle.imageset/Contents.json b/PHDemo/PHDemo/Assets.xcassets/prohud.rainbow.circle.imageset/Contents.json deleted file mode 100644 index 266990e..0000000 --- a/PHDemo/PHDemo/Assets.xcassets/prohud.rainbow.circle.imageset/Contents.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "images" : [ - { - "idiom" : "universal", - "scale" : "1x" - }, - { - "filename" : "prohud.rainbow.circle@2x.png", - "idiom" : "universal", - "scale" : "2x" - }, - { - "filename" : "prohud.rainbow.circle@3x.png", - "idiom" : "universal", - "scale" : "3x" - } - ], - "info" : { - "author" : "xcode", - "version" : 1 - } -} diff --git a/PHDemo/PHDemo/Assets.xcassets/prohud.rainbow.circle.imageset/prohud.rainbow.circle@2x.png b/PHDemo/PHDemo/Assets.xcassets/prohud.rainbow.circle.imageset/prohud.rainbow.circle@2x.png deleted file mode 100644 index 51fdd40..0000000 Binary files a/PHDemo/PHDemo/Assets.xcassets/prohud.rainbow.circle.imageset/prohud.rainbow.circle@2x.png and /dev/null differ diff --git a/PHDemo/PHDemo/Assets.xcassets/prohud.rainbow.circle.imageset/prohud.rainbow.circle@3x.png b/PHDemo/PHDemo/Assets.xcassets/prohud.rainbow.circle.imageset/prohud.rainbow.circle@3x.png deleted file mode 100644 index d6d457b..0000000 Binary files a/PHDemo/PHDemo/Assets.xcassets/prohud.rainbow.circle.imageset/prohud.rainbow.circle@3x.png and /dev/null differ diff --git a/PHDemo/PHDemo/Assets.xcassets/prohud.trash.imageset/prohud.trash@2x.png b/PHDemo/PHDemo/Assets.xcassets/prohud.trash.imageset/prohud.trash@2x.png deleted file mode 100644 index 25fb085..0000000 Binary files a/PHDemo/PHDemo/Assets.xcassets/prohud.trash.imageset/prohud.trash@2x.png and /dev/null differ diff --git a/PHDemo/PHDemo/Assets.xcassets/prohud.trash.imageset/prohud.trash@3x.png b/PHDemo/PHDemo/Assets.xcassets/prohud.trash.imageset/prohud.trash@3x.png deleted file mode 100644 index 1411e5e..0000000 Binary files a/PHDemo/PHDemo/Assets.xcassets/prohud.trash.imageset/prohud.trash@3x.png and /dev/null differ diff --git a/PHDemo/PHDemo/Scenes.swift b/PHDemo/PHDemo/Scenes.swift index eac7ca0..ef7410a 100644 --- a/PHDemo/PHDemo/Scenes.swift +++ b/PHDemo/PHDemo/Scenes.swift @@ -15,17 +15,30 @@ public extension ViewModel { // static var note: ViewModel { // ViewModel(icon: UIImage(named: "prohud.note")) // } + // MARK: note + static var note: ViewModel { + .init(icon: UIImage(named: "demo.note")) + } + static func note(_ seconds: TimeInterval) -> ViewModel { + .init(icon: UIImage(named: "demo.note"), duration: seconds) + } static var msg: ViewModel { - ViewModel(icon: UIImage(inProHUD: "prohud.message")) + ViewModel(icon: UIImage(named: "demo.message")) } static func msg(_ seconds: TimeInterval) -> ViewModel { - ViewModel(icon: UIImage(inProHUD: "prohud.message"), duration: seconds) + ViewModel(icon: UIImage(named: "demo.message"), duration: seconds) } - static var loading: ViewModel { - let obj = ViewModel(icon: UIImage(named: "prohud.rainbow.circle")) - obj.rotation = .init(repeatCount: .infinity) - return obj + static var delete: ViewModel { + ViewModel(icon: UIImage(named: "demo.trash")) } + // MARK: confirm + static var confirm: ViewModel { + .init(icon: UIImage(named: "demo.questionmark")) + } + static func confirm(_ seconds: TimeInterval) -> ViewModel { + .init(icon: UIImage(named: "demo.questionmark"), duration: seconds) + } + // static func loading(_ seconds: TimeInterval) -> ViewModel { // let obj = ViewModel(icon: UIImage(named: "prohud.rainbow.circle"), duration: seconds) // obj.rotation = .init(repeatCount: .infinity) diff --git a/PHDemo/PHDemo/ToastVC.swift b/PHDemo/PHDemo/ToastVC.swift index 56c3822..551ca9d 100644 --- a/PHDemo/PHDemo/ToastVC.swift +++ b/PHDemo/PHDemo/ToastVC.swift @@ -18,6 +18,14 @@ class ToastVC: ListVC { header.titleLabel.text = "ProHUD.Toast" header.detailLabel.text = message + Toast.Configuration.shared { config in + config.contentViewMask { mask in + mask.backgroundColor = .clear + mask.effect = UIBlurEffect(style: .systemChromeMaterial) + } + } + + list.add(title: "默认布局") { section in section.add(title: "标题 + 正文") { Toast(.title(title).message(message)).push() @@ -29,7 +37,6 @@ class ToastVC: ListVC { let s1 = "正在加载" let s2 = "这条通知4s后消失" let toast = Toast(.loading(4).title(s1).message(s2)) - toast.identifier = "loading" toast.push() toast.update(progress: 0) DispatchQueue.main.asyncAfter(deadline: .now() + 1) { @@ -39,8 +46,8 @@ class ToastVC: ListVC { toast.update(progress: 1) } DispatchQueue.main.asyncAfter(deadline: .now() + 2.5) { - Toast.find(identifier: "loading") { toast in - toast.vm = .success(2).title("加载成功").message("这条通知2s后消失") + toast.update { toast in + toast.vm = .success(10).title("加载成功").message("这条通知10s后消失") } } } @@ -50,13 +57,13 @@ class ToastVC: ListVC { } list.add(title: "事件管理") { section in - section.add(title: "全局点击事件") { + section.add(title: "点击事件") { let title = "您收到了一条消息" - let message = "这条消息5s后消失,点击回复" - Toast(.msg(5).title(title).message(message)) { toast in + let message = "点击通知横幅任意处即可回复" + Toast(.msg.title(title).message(message)) { toast in toast.onTapped { toast in toast.pop() - testAlert() + Alert(.success(1).message("操作成功")).push() } } } @@ -87,8 +94,11 @@ class ToastVC: ListVC { } } toast.add(action: "同意") { toast in - Alert.find(identifier: "Dracarys")?.pop() + Alert.find(identifier: "Dracarys", update: { alert in + alert.pop() + }) toast.pop() + Alert(.success(1).message("Good choice!")).push() } } } @@ -124,7 +134,9 @@ class ToastVC: ListVC { } } section.add(title: "移除指定实例") { - Toast.find(identifier: "loading")?.pop() + Toast.find(identifier: "loading") { toast in + toast.pop() + } } } diff --git a/Resources/Icons.sketch b/Resources/Icons.sketch new file mode 100644 index 0000000..fe8ba27 Binary files /dev/null and b/Resources/Icons.sketch differ diff --git a/Resources/demo.message@2x.png b/Resources/demo.message@2x.png new file mode 100644 index 0000000..7bf8c1b Binary files /dev/null and b/Resources/demo.message@2x.png differ diff --git a/Resources/demo.message@3x.png b/Resources/demo.message@3x.png new file mode 100644 index 0000000..7436293 Binary files /dev/null and b/Resources/demo.message@3x.png differ diff --git a/Resources/demo.note@2x.png b/Resources/demo.note@2x.png new file mode 100644 index 0000000..ee6a901 Binary files /dev/null and b/Resources/demo.note@2x.png differ diff --git a/Resources/demo.note@3x.png b/Resources/demo.note@3x.png new file mode 100644 index 0000000..4cf439d Binary files /dev/null and b/Resources/demo.note@3x.png differ diff --git a/Resources/demo.questionmark@2x.png b/Resources/demo.questionmark@2x.png new file mode 100644 index 0000000..5251a23 Binary files /dev/null and b/Resources/demo.questionmark@2x.png differ diff --git a/Resources/demo.questionmark@3x.png b/Resources/demo.questionmark@3x.png new file mode 100644 index 0000000..5a8a69e Binary files /dev/null and b/Resources/demo.questionmark@3x.png differ diff --git a/Resources/demo.trash@2x.png b/Resources/demo.trash@2x.png new file mode 100644 index 0000000..73802ec Binary files /dev/null and b/Resources/demo.trash@2x.png differ diff --git a/Resources/demo.trash@3x.png b/Resources/demo.trash@3x.png new file mode 100644 index 0000000..571bd08 Binary files /dev/null and b/Resources/demo.trash@3x.png differ diff --git a/Resources/prohud.checkmark@2x.png b/Resources/prohud.checkmark@2x.png new file mode 100644 index 0000000..274eeee Binary files /dev/null and b/Resources/prohud.checkmark@2x.png differ diff --git a/Resources/prohud.checkmark@3x.png b/Resources/prohud.checkmark@3x.png new file mode 100644 index 0000000..4e1c488 Binary files /dev/null and b/Resources/prohud.checkmark@3x.png differ diff --git a/Resources/prohud.exclamationmark@2x.png b/Resources/prohud.exclamationmark@2x.png new file mode 100644 index 0000000..548aeab Binary files /dev/null and b/Resources/prohud.exclamationmark@2x.png differ diff --git a/Resources/prohud.exclamationmark@3x.png b/Resources/prohud.exclamationmark@3x.png new file mode 100644 index 0000000..32c1f05 Binary files /dev/null and b/Resources/prohud.exclamationmark@3x.png differ diff --git a/Resources/prohud.rainbow@2x.png b/Resources/prohud.rainbow@2x.png new file mode 100644 index 0000000..be343d9 Binary files /dev/null and b/Resources/prohud.rainbow@2x.png differ diff --git a/Resources/prohud.rainbow@3x.png b/Resources/prohud.rainbow@3x.png new file mode 100644 index 0000000..458f252 Binary files /dev/null and b/Resources/prohud.rainbow@3x.png differ diff --git a/Resources/prohud.windmill@2x.png b/Resources/prohud.windmill@2x.png new file mode 100644 index 0000000..79b5bde Binary files /dev/null and b/Resources/prohud.windmill@2x.png differ diff --git a/Resources/prohud.windmill@3x.png b/Resources/prohud.windmill@3x.png new file mode 100644 index 0000000..4e4a9ea Binary files /dev/null and b/Resources/prohud.windmill@3x.png differ diff --git a/Resources/prohud.xmark@2x.png b/Resources/prohud.xmark@2x.png new file mode 100644 index 0000000..77a4218 Binary files /dev/null and b/Resources/prohud.xmark@2x.png differ diff --git a/Resources/prohud.xmark@3x.png b/Resources/prohud.xmark@3x.png new file mode 100644 index 0000000..f5e49f2 Binary files /dev/null and b/Resources/prohud.xmark@3x.png differ diff --git a/Sources/ProHUD/Alert/Alert.swift b/Sources/ProHUD/Alert/Alert.swift index 5a035bb..bdc8677 100644 --- a/Sources/ProHUD/Alert/Alert.swift +++ b/Sources/ProHUD/Alert/Alert.swift @@ -33,8 +33,13 @@ public class Alert: ProHUD.Controller { return stack }() - /// 图片 - public var imageView = UIImageView() + /// 图标 + public lazy var imageView: UIImageView = { + let imgv = UIImageView() + imgv.contentMode = .scaleAspectFit + imgv.tintColor = view.tintColor + return imgv + }() /// 标题 public lazy var titleLabel: UILabel = { diff --git a/Sources/ProHUD/Alert/AlertDefaultLayout.swift b/Sources/ProHUD/Alert/AlertDefaultLayout.swift index b4b506b..deaf9b5 100644 --- a/Sources/ProHUD/Alert/AlertDefaultLayout.swift +++ b/Sources/ProHUD/Alert/AlertDefaultLayout.swift @@ -29,6 +29,7 @@ extension Alert: DefaultLayout { return } // default layout + // 更新图片 setupImageView() @@ -53,14 +54,6 @@ extension Alert: DefaultLayout { self.view.layoutIfNeeded() } } - // id 包含 .rotate 的会自动旋转 - if let rotation = vm.rotation { - startRotate(rotation) - } - // 设置持续时间 - vm.timeoutHandler = DispatchWorkItem(block: { [weak self] in - self?.pop() - }) } @@ -133,16 +126,6 @@ extension Alert: DefaultLayout { extension Alert { func setupImageView() { - guard let icon = vm.icon else { return } - imageView.image = icon - contentStack.insertArrangedSubview(imageView, at: 0) - imageView.contentMode = .scaleAspectFit - imageView.snp.remakeConstraints { (mk) in - mk.top.left.greaterThanOrEqualTo(contentView).inset(config.padding*2.25) - mk.right.bottom.lessThanOrEqualTo(contentView).inset(config.padding*2.25) - mk.width.equalTo(config.iconSize.width) - mk.height.equalTo(config.iconSize.height) - } // 移除动画 stopRotate(animateLayer) animateLayer = nil @@ -150,6 +133,28 @@ extension Alert { // 移除进度 progressView?.removeFromSuperview() + + if vm.icon != nil { + imageView.image = vm.icon + if imageView.superview == nil { + contentStack.insertArrangedSubview(imageView, at: 0) + imageView.snp.remakeConstraints { (mk) in + mk.top.left.greaterThanOrEqualTo(contentView).inset(config.padding*2.25) + mk.right.bottom.lessThanOrEqualTo(contentView).inset(config.padding*2.25) + mk.width.equalTo(config.iconSize.width) + mk.height.equalTo(config.iconSize.height) + } + } + if let rotation = vm.rotation { + startRotate(rotation) + } + } else { + if contentStack.arrangedSubviews.contains(imageView) { + contentStack.removeArrangedSubview(imageView) + } + imageView.removeFromSuperview() + } + } func setupTextStack() { let titleCount = vm.title?.count ?? 0 diff --git a/Sources/ProHUD/Alert/AlertManager.swift b/Sources/ProHUD/Alert/AlertManager.swift index 1526a0e..0d7d62f 100644 --- a/Sources/ProHUD/Alert/AlertManager.swift +++ b/Sources/ProHUD/Alert/AlertManager.swift @@ -85,7 +85,7 @@ extension Alert { /// 更新HUD实例 /// - Parameter callback: 实例更新代码 - func update(handler: @escaping (_ alert: Alert) -> Void) { + public func update(handler: @escaping (_ alert: Alert) -> Void) { handler(self) reloadData() UIView.animateEaseOut(duration: config.animateDurationForReloadByDefault) { @@ -96,14 +96,12 @@ extension Alert { /// 查找HUD实例 /// - Parameter identifier: 唯一标识符 /// - Returns: HUD实例 - public static func find(identifier: String, update handler: ((_ alert: Alert) -> Void)? = nil) -> Alert? { - guard let vc = AlertWindow.alerts.last(where: { $0.identifier == identifier }) else { - return nil - } + @discardableResult public static func find(identifier: String, update handler: ((_ alert: Alert) -> Void)? = nil) -> [Alert] { + let arr = AlertWindow.alerts.filter({ $0.identifier == identifier }) if let handler = handler { - vc.update(handler: handler) + arr.forEach({ $0.update(handler: handler) }) } - return vc + return arr } } diff --git a/Sources/ProHUD/Core/Models/Configuration.swift b/Sources/ProHUD/Core/Models/Configuration.swift index 7afaac3..95ef404 100644 --- a/Sources/ProHUD/Core/Models/Configuration.swift +++ b/Sources/ProHUD/Core/Models/Configuration.swift @@ -104,7 +104,7 @@ public class Configuration: NSObject { // MARK: 图标样式 /// 图标尺寸 - public var iconSize = CGSize(width: 48, height: 48) + public var iconSize = CGSize(width: 44, height: 44) // MARK: 文本样式 /// 标题字体 diff --git a/Sources/ProHUD/Core/Models/ViewModel.swift b/Sources/ProHUD/Core/Models/ViewModel.swift index 53e3b75..bfe5672 100644 --- a/Sources/ProHUD/Core/Models/ViewModel.swift +++ b/Sources/ProHUD/Core/Models/ViewModel.swift @@ -105,21 +105,14 @@ public extension ViewModel { return obj } - // MARK: note - static var note: ViewModel { - .init(icon: UIImage(inProHUD: "prohud.note")) - } - static func note(_ seconds: TimeInterval) -> ViewModel { - .init(icon: UIImage(inProHUD: "prohud.note"), duration: seconds) - } // MARK: loading static var loading: ViewModel { - let obj = ViewModel(icon: UIImage(inProHUD: "prohud.rainbow.circle")) + let obj = ViewModel(icon: UIImage(inProHUD: "prohud.windmill")) obj.rotation = .init(repeatCount: .infinity) return obj } static func loading(_ seconds: TimeInterval) -> ViewModel { - let obj = ViewModel(icon: UIImage(inProHUD: "prohud.rainbow.circle"), duration: seconds) + let obj = ViewModel(icon: UIImage(inProHUD: "prohud.windmill"), duration: seconds) obj.rotation = .init(repeatCount: .infinity) return obj } @@ -148,12 +141,4 @@ public extension ViewModel { static var failure: ViewModel { error } static func failure(_ seconds: TimeInterval) -> ViewModel { error(seconds) } - // MARK: confirm - static var confirm: ViewModel { - .init(icon: UIImage(inProHUD: "prohud.questionmark")) - } - static func confirm(_ seconds: TimeInterval) -> ViewModel { - .init(icon: UIImage(inProHUD: "prohud.questionmark"), duration: seconds) - } - } diff --git a/Sources/ProHUD/Core/Utils/RotateAnimation.swift b/Sources/ProHUD/Core/Utils/RotateAnimation.swift index 2f13d88..50c0b56 100644 --- a/Sources/ProHUD/Core/Utils/RotateAnimation.swift +++ b/Sources/ProHUD/Core/Utils/RotateAnimation.swift @@ -12,13 +12,16 @@ extension LoadingAnimation { /// 更新进度(如果需要显示进度,需要先调用一次 updateProgress(0) 来初始化) /// - Parameter progress: 进度(0~1) public func update(progress: CGFloat) { + guard isViewLoaded else { return } guard let superview = imageView.superview else { return } if progressView == nil { - let v = ProgressView() + let width = imageView.frame.size.width + ProgressView.lineWidth * 2 + let v = ProgressView(frame: .init(origin: .zero, size: .init(width: width, height: width))) superview.addSubview(v) + v.tintColor = superview.tintColor v.snp.remakeConstraints { (mk) in mk.center.equalTo(imageView) - mk.width.height.equalTo(28) + mk.width.height.equalTo(width) } progressView = v } diff --git a/Sources/ProHUD/Core/Views/ProgressView.swift b/Sources/ProHUD/Core/Views/ProgressView.swift index 184c919..3a6572e 100644 --- a/Sources/ProHUD/Core/Views/ProgressView.swift +++ b/Sources/ProHUD/Core/Views/ProgressView.swift @@ -12,23 +12,41 @@ public class ProgressView: UIView { var progressLayer = CAShapeLayer() + static var lineWidth: CGFloat { 4 } + + public override var tintColor: UIColor! { + didSet { + progressLayer.strokeColor = tintColor.cgColor + } + } + override init(frame: CGRect) { + let lineWidth = Self.lineWidth // 容器宽度 - let maxSize = CGFloat(28) - super.init(frame: .init(x: 0, y: 0, width: maxSize, height: maxSize)) - layer.cornerRadius = maxSize / 2 + let size = CGFloat.maximum(frame.height, frame.width) + super.init(frame: .init(x: 0, y: 0, width: size, height: size)) + layer.cornerRadius = size / 2 layer.masksToBounds = true - // 进度圆半径 - let radius = maxSize / 2 - 4 - backgroundColor = .white + // 圆环路径 + let path = UIBezierPath(arcCenter: CGPoint(x: size / 2, y: size / 2), radius: (size - lineWidth) / 2, startAngle: -CGFloat.pi*0.5, endAngle: CGFloat.pi * 1.5, clockwise: true) - let path = UIBezierPath(arcCenter: CGPoint(x: 14, y: 14), radius: radius/2, startAngle: -CGFloat.pi*0.5, endAngle: CGFloat.pi * 1.5, clockwise: true) + // 轨道 + let bgLayer = CAShapeLayer() + bgLayer.fillColor = UIColor.clear.cgColor + bgLayer.path = path.cgPath + bgLayer.strokeColor = UIColor.white.cgColor + bgLayer.lineWidth = lineWidth + bgLayer.lineCap = .round + bgLayer.strokeStart = 0 + bgLayer.strokeEnd = 1 + layer.addSublayer(bgLayer) + // 进度 progressLayer.fillColor = UIColor.clear.cgColor progressLayer.path = path.cgPath - progressLayer.strokeColor = tintColor.cgColor - progressLayer.lineWidth = radius + progressLayer.lineWidth = lineWidth + progressLayer.lineCap = .round progressLayer.strokeStart = 0 progressLayer.strokeEnd = 0 layer.addSublayer(progressLayer) diff --git a/Sources/ProHUD/Resources/ProHUD.xcassets/Contents.json b/Sources/ProHUD/Resources/ProHUD.xcassets/Contents.json index da4a164..73c0059 100644 --- a/Sources/ProHUD/Resources/ProHUD.xcassets/Contents.json +++ b/Sources/ProHUD/Resources/ProHUD.xcassets/Contents.json @@ -1,6 +1,6 @@ { "info" : { - "version" : 1, - "author" : "xcode" + "author" : "xcode", + "version" : 1 } -} \ No newline at end of file +} diff --git a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.checkmark.imageset/prohud.checkmark@2x.png b/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.checkmark.imageset/prohud.checkmark@2x.png index 0fecb2b..274eeee 100644 Binary files a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.checkmark.imageset/prohud.checkmark@2x.png and b/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.checkmark.imageset/prohud.checkmark@2x.png differ diff --git a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.checkmark.imageset/prohud.checkmark@3x.png b/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.checkmark.imageset/prohud.checkmark@3x.png index 9f75dfc..4e1c488 100644 Binary files a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.checkmark.imageset/prohud.checkmark@3x.png and b/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.checkmark.imageset/prohud.checkmark@3x.png differ diff --git a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.exclamationmark.imageset/prohud.exclamationmark@2x.png b/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.exclamationmark.imageset/prohud.exclamationmark@2x.png index d84bf63..548aeab 100644 Binary files a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.exclamationmark.imageset/prohud.exclamationmark@2x.png and b/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.exclamationmark.imageset/prohud.exclamationmark@2x.png differ diff --git a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.exclamationmark.imageset/prohud.exclamationmark@3x.png b/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.exclamationmark.imageset/prohud.exclamationmark@3x.png index 80e07cb..32c1f05 100644 Binary files a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.exclamationmark.imageset/prohud.exclamationmark@3x.png and b/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.exclamationmark.imageset/prohud.exclamationmark@3x.png differ diff --git a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.message.imageset/prohud.message@2x.png b/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.message.imageset/prohud.message@2x.png deleted file mode 100644 index 6d256b6..0000000 Binary files a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.message.imageset/prohud.message@2x.png and /dev/null differ diff --git a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.message.imageset/prohud.message@3x.png b/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.message.imageset/prohud.message@3x.png deleted file mode 100644 index c37d8b0..0000000 Binary files a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.message.imageset/prohud.message@3x.png and /dev/null differ diff --git a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.note.imageset/prohud.note@2x.png b/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.note.imageset/prohud.note@2x.png deleted file mode 100644 index 44c986e..0000000 Binary files a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.note.imageset/prohud.note@2x.png and /dev/null differ diff --git a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.note.imageset/prohud.note@3x.png b/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.note.imageset/prohud.note@3x.png deleted file mode 100644 index b7e326f..0000000 Binary files a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.note.imageset/prohud.note@3x.png and /dev/null differ diff --git a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.privacy.imageset/prohud.privacy@2x.png b/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.privacy.imageset/prohud.privacy@2x.png deleted file mode 100644 index cbd1022..0000000 Binary files a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.privacy.imageset/prohud.privacy@2x.png and /dev/null differ diff --git a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.privacy.imageset/prohud.privacy@3x.png b/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.privacy.imageset/prohud.privacy@3x.png deleted file mode 100644 index 1b42f67..0000000 Binary files a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.privacy.imageset/prohud.privacy@3x.png and /dev/null differ diff --git a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.questionmark.imageset/Contents.json b/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.questionmark.imageset/Contents.json deleted file mode 100644 index ae5d524..0000000 --- a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.questionmark.imageset/Contents.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "images" : [ - { - "idiom" : "universal", - "scale" : "1x" - }, - { - "filename" : "prohud.questionmark@2x.png", - "idiom" : "universal", - "scale" : "2x" - }, - { - "filename" : "prohud.questionmark@3x.png", - "idiom" : "universal", - "scale" : "3x" - } - ], - "info" : { - "author" : "xcode", - "version" : 1 - } -} diff --git a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.questionmark.imageset/prohud.questionmark@2x.png b/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.questionmark.imageset/prohud.questionmark@2x.png deleted file mode 100644 index dfd59f5..0000000 Binary files a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.questionmark.imageset/prohud.questionmark@2x.png and /dev/null differ diff --git a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.questionmark.imageset/prohud.questionmark@3x.png b/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.questionmark.imageset/prohud.questionmark@3x.png deleted file mode 100644 index 8154a9f..0000000 Binary files a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.questionmark.imageset/prohud.questionmark@3x.png and /dev/null differ diff --git a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.rainbow.circle.imageset/Contents.json b/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.rainbow.circle.imageset/Contents.json deleted file mode 100644 index 266990e..0000000 --- a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.rainbow.circle.imageset/Contents.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "images" : [ - { - "idiom" : "universal", - "scale" : "1x" - }, - { - "filename" : "prohud.rainbow.circle@2x.png", - "idiom" : "universal", - "scale" : "2x" - }, - { - "filename" : "prohud.rainbow.circle@3x.png", - "idiom" : "universal", - "scale" : "3x" - } - ], - "info" : { - "author" : "xcode", - "version" : 1 - } -} diff --git a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.rainbow.circle.imageset/prohud.rainbow.circle@2x.png b/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.rainbow.circle.imageset/prohud.rainbow.circle@2x.png deleted file mode 100644 index 51fdd40..0000000 Binary files a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.rainbow.circle.imageset/prohud.rainbow.circle@2x.png and /dev/null differ diff --git a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.rainbow.circle.imageset/prohud.rainbow.circle@3x.png b/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.rainbow.circle.imageset/prohud.rainbow.circle@3x.png deleted file mode 100644 index d6d457b..0000000 Binary files a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.rainbow.circle.imageset/prohud.rainbow.circle@3x.png and /dev/null differ diff --git a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.privacy.imageset/Contents.json b/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.rainbow.imageset/Contents.json similarity index 75% rename from Sources/ProHUD/Resources/ProHUD.xcassets/prohud.privacy.imageset/Contents.json rename to Sources/ProHUD/Resources/ProHUD.xcassets/prohud.rainbow.imageset/Contents.json index ebaf379..9486bc4 100644 --- a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.privacy.imageset/Contents.json +++ b/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.rainbow.imageset/Contents.json @@ -5,12 +5,12 @@ "scale" : "1x" }, { - "filename" : "prohud.privacy@2x.png", + "filename" : "prohud.rainbow@2x.png", "idiom" : "universal", "scale" : "2x" }, { - "filename" : "prohud.privacy@3x.png", + "filename" : "prohud.rainbow@3x.png", "idiom" : "universal", "scale" : "3x" } diff --git a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.rainbow.imageset/prohud.rainbow@2x.png b/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.rainbow.imageset/prohud.rainbow@2x.png new file mode 100644 index 0000000..be343d9 Binary files /dev/null and b/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.rainbow.imageset/prohud.rainbow@2x.png differ diff --git a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.rainbow.imageset/prohud.rainbow@3x.png b/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.rainbow.imageset/prohud.rainbow@3x.png new file mode 100644 index 0000000..458f252 Binary files /dev/null and b/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.rainbow.imageset/prohud.rainbow@3x.png differ diff --git a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.trash.imageset/prohud.trash@2x.png b/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.trash.imageset/prohud.trash@2x.png deleted file mode 100644 index 25fb085..0000000 Binary files a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.trash.imageset/prohud.trash@2x.png and /dev/null differ diff --git a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.trash.imageset/prohud.trash@3x.png b/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.trash.imageset/prohud.trash@3x.png deleted file mode 100644 index 1411e5e..0000000 Binary files a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.trash.imageset/prohud.trash@3x.png and /dev/null differ diff --git a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.windmill.imageset/prohud.windmill@2x.png b/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.windmill.imageset/prohud.windmill@2x.png index 0d0f0d5..79b5bde 100644 Binary files a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.windmill.imageset/prohud.windmill@2x.png and b/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.windmill.imageset/prohud.windmill@2x.png differ diff --git a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.windmill.imageset/prohud.windmill@3x.png b/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.windmill.imageset/prohud.windmill@3x.png index d42e6cd..4e4a9ea 100644 Binary files a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.windmill.imageset/prohud.windmill@3x.png and b/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.windmill.imageset/prohud.windmill@3x.png differ diff --git a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.xmark.imageset/prohud.xmark@2x.png b/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.xmark.imageset/prohud.xmark@2x.png index ed77e18..77a4218 100644 Binary files a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.xmark.imageset/prohud.xmark@2x.png and b/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.xmark.imageset/prohud.xmark@2x.png differ diff --git a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.xmark.imageset/prohud.xmark@3x.png b/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.xmark.imageset/prohud.xmark@3x.png index 448d1d0..f5e49f2 100644 Binary files a/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.xmark.imageset/prohud.xmark@3x.png and b/Sources/ProHUD/Resources/ProHUD.xcassets/prohud.xmark.imageset/prohud.xmark@3x.png differ diff --git a/Sources/ProHUD/Toast/ToastConfiguration.swift b/Sources/ProHUD/Toast/ToastConfiguration.swift index 77326f0..978c896 100644 --- a/Sources/ProHUD/Toast/ToastConfiguration.swift +++ b/Sources/ProHUD/Toast/ToastConfiguration.swift @@ -31,15 +31,15 @@ public extension Toast { } override var titleFontByDefault: UIFont { - titleFont ?? .systemFont(ofSize: 19, weight: .bold) + titleFont ?? .systemFont(ofSize: 18, weight: .bold) } override var boldTextFontByDefault: UIFont { - boldTextFont ?? .systemFont(ofSize: 17, weight: .bold) + boldTextFont ?? .systemFont(ofSize: 16, weight: .bold) } override var bodyFontByDefault: UIFont { - bodyFont ?? .systemFont(ofSize: 17, weight: .regular) + bodyFont ?? .systemFont(ofSize: 16, weight: .regular) } override var animateDurationForBuildInByDefault: CGFloat { diff --git a/Sources/ProHUD/Toast/ToastDefaultLayout.swift b/Sources/ProHUD/Toast/ToastDefaultLayout.swift index 98df8ed..e361a6b 100644 --- a/Sources/ProHUD/Toast/ToastDefaultLayout.swift +++ b/Sources/ProHUD/Toast/ToastDefaultLayout.swift @@ -77,17 +77,7 @@ extension Toast: DefaultLayout { self?.pop() }) - // 移除动画 - stopRotate(animateLayer) - animateLayer = nil - animation = nil - - // 移除进度 - progressView?.removeFromSuperview() - // 开始动画 - if let rotation = vm.rotation { - startRotate(rotation) - } + setupImageView() } @@ -126,4 +116,20 @@ extension Toast { contentStack.addArrangedSubview(sup) } } + + func setupImageView() { + // 移除动画 + stopRotate(animateLayer) + animateLayer = nil + animation = nil + + // 移除进度 + progressView?.removeFromSuperview() + + imageView.image = vm.icon + if let rotation = vm.rotation { + startRotate(rotation) + } + + } } diff --git a/Sources/ProHUD/Toast/ToastManager.swift b/Sources/ProHUD/Toast/ToastManager.swift index 4c788b3..734c240 100644 --- a/Sources/ProHUD/Toast/ToastManager.swift +++ b/Sources/ProHUD/Toast/ToastManager.swift @@ -40,7 +40,7 @@ extension Toast { /// 更新HUD实例 /// - Parameter callback: 实例更新代码 - func update(handler: @escaping (_ toast: Toast) -> Void) { + public func update(handler: @escaping (_ toast: Toast) -> Void) { handler(self) reloadData() UIView.animateEaseOut(duration: config.animateDurationForReloadByDefault) { @@ -51,14 +51,12 @@ extension Toast { /// 查找HUD实例 /// - Parameter identifier: 唯一标识符 /// - Returns: HUD实例 - @discardableResult public static func find(identifier: String, update handler: ((_ toast: Toast) -> Void)? = nil) -> Toast? { - guard let vc = ToastWindow.windows.last(where: { $0.toast.identifier == identifier })?.toast else { - return nil - } + @discardableResult public static func find(identifier: String, update handler: ((_ toast: Toast) -> Void)? = nil) -> [Toast] { + let arr = ToastWindow.windows.compactMap({ $0.toast }).filter({ $0.identifier == identifier }) if let handler = handler { - vc.update(handler: handler) + arr.forEach({ $0.update(handler: handler) }) } - return vc + return arr } }