diff --git a/PHDemo/PHDemo/DemoToastVC.swift b/PHDemo/PHDemo/DemoToastVC.swift index 7e2cfec..9245347 100644 --- a/PHDemo/PHDemo/DemoToastVC.swift +++ b/PHDemo/PHDemo/DemoToastVC.swift @@ -118,6 +118,12 @@ class DemoToastVC: ListVC { section.add(title: "标题 + 正文") { TestToast(.title(title).message(message)) } + section.add(title: "防止重复") { + TestToast(.identifier("toast").title(title).message(message).duration(2)) + DispatchQueue.main.asyncAfter(deadline: .now() + 1) { + TestToast(.identifier("toast").title(title).message(message).duration(2)) + } + } section.add(title: "一段长文本") { // Toast(.message(message)) // 可以简写成这样: diff --git a/Sources/ProHUD/Alert/AlertTarget.swift b/Sources/ProHUD/Alert/AlertTarget.swift index ff6335e..0b11ec3 100644 --- a/Sources/ProHUD/Alert/AlertTarget.swift +++ b/Sources/ProHUD/Alert/AlertTarget.swift @@ -73,8 +73,12 @@ open class AlertTarget: BaseController, HUDTargetType { /// 视图模型 @objc public var vm: AlertViewModel? { + willSet { + vm?.cancelTimer() + } didSet { vm?.vc = self + vm?.restartTimer() } } diff --git a/Sources/ProHUD/Capsule/CapsuleTarget.swift b/Sources/ProHUD/Capsule/CapsuleTarget.swift index a1463ca..62781d5 100644 --- a/Sources/ProHUD/Capsule/CapsuleTarget.swift +++ b/Sources/ProHUD/Capsule/CapsuleTarget.swift @@ -48,6 +48,7 @@ open class CapsuleTarget: BaseController, HUDTargetType { } didSet { vm?.vc = self + vm?.restartTimer() } } diff --git a/Sources/ProHUD/Toast/ToastTarget.swift b/Sources/ProHUD/Toast/ToastTarget.swift index 8417e35..f7d96f6 100644 --- a/Sources/ProHUD/Toast/ToastTarget.swift +++ b/Sources/ProHUD/Toast/ToastTarget.swift @@ -83,8 +83,12 @@ open class ToastTarget: BaseController, HUDTargetType { /// 视图模型 @objc public var vm: ToastViewModel? { + willSet { + vm?.cancelTimer() + } didSet { vm?.vc = self + vm?.restartTimer() } }