From 69ae2c86a78e4bc685eb663f2f2e3545e9e823da Mon Sep 17 00:00:00 2001 From: Suyeol Jeon Date: Tue, 15 Dec 2015 15:26:42 +0900 Subject: [PATCH] Bring JLToastWindow to top when another window is being shown. --- JLToast/JLToastWindow.swift | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/JLToast/JLToastWindow.swift b/JLToast/JLToastWindow.swift index a50610e..550b7ba 100644 --- a/JLToast/JLToastWindow.swift +++ b/JLToast/JLToastWindow.swift @@ -32,12 +32,25 @@ public class JLToastWindow: UIWindow { public override init(frame: CGRect) { super.init(frame: frame) + NSNotificationCenter.defaultCenter().addObserver(self, + selector: "bringWindowToTop:", + name: UIWindowDidBecomeVisibleNotification, + object: nil + ) } required public init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } + /// Bring JLToastWindow to top when another window is being shown. + func bringWindowToTop(notification: NSNotification) { + if !(notification.object is JLToastWindow) { + self.dynamicType.sharedWindow.hidden = true + self.dynamicType.sharedWindow.hidden = false + } + } + }