Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent a UIWindow to be a key window?

Tags:

When I show an alert with UIAlertController, the alert itself presented in a new window. (for now at least) And when the alert window dismisses, system seems to set a random window key-window.

I am presenting a new "banner" window to render some banners over status-bar (AppStore compatibility is out of topic here), and usually, this "banner" window becomes next key window, and causes many problems on user input and first responder management.

So, I want to prevent this "banner" window to become a key window, but I cannot figure out how. For now, as a workaround, I am just re-setting my main window to be a key window again as soon as that "banner" window becomes key window. But it doesn't feel really good.

How can I prevent a window to become a key window?

like image 988
eonil Avatar asked Jun 30 '16 07:06

eonil


1 Answers

As a workaround, we can set main window key again as soon as the "banner" window becomes a key like this.

class BannerWindow: UIWindow {
    weak var mainWindow: UIWindow?
    override func becomeKeyWindow() {
        super.becomeKeyWindow()
        mainWindow?.makeKeyWindow()
    }
}
like image 191
eonil Avatar answered Oct 03 '22 17:10

eonil