Reputation: 33048
Recently I've been wondering about the fact that that an iOS app only has one UIWindow
.
It does not seem to be an issue to create another UIWindow
and place it on screen.
My question is kind of vague, but I'm interested in:
UIWindow
that cannot be done in other ways?UIWindow
instances?UIWindow
to display popover like views on iPhone. Is this a good way of doing it? Why? Why not?UIWindow
?It's not that I'm missing something. I have never felt the need to create another UIWindow
instance but maybe it would allow doing amazing things I'm not aware of! :-)
I'm hoping that it might help me solve this problem:
I need to add a "cover view" over whatever is currently displayed. It should also work if there are already one or more modal controllers presented. If I add a UIView
to the root controller's view, the modal controllers sit on top, so do the popover controllers.
If I present the cover view modally and there is already a modal controller, only part of the screen is covered.
Upvotes: 93
Views: 16532
Reputation: 324
Here is Apple's Documentation for better understanding UIWindow: https://developer.apple.com/library/archive/documentation/WindowsViews/Conceptual/WindowAndScreenGuide/WindowScreenRolesinApp/WindowScreenRolesinApp.html
One good though specific reason to use multiple instances of UIWindow is when you need to video record the app screen. You may not want to include certain elements (recording button, recording status, etc.) in the final recorded video, so you can put those elements in a separate UIWindow on top.
In fact, if you are using ReplayKit, you will have to use a separate UIWindow for these excluded UI elements. More info here: https://medium.com/ar-tips-and-tricks/how-to-record-a-screen-capture-with-replaykit-whilst-hiding-the-hud-element-bedcca8e31e
Upvotes: 0
Reputation: 33048
Starting with Rob's answer I played around a bit and would like to write down some notes for others trying to get information on this topic:
UIWindow
. Just create one and makeKeyAndVisible
. Done.UIWindow
covers everything, even modals, popovers, etc. Brilliant!UIWindow
is always portrait implicitly. It does no rotate. You'll have to add a controller as the new window's root controller and let that handle rotation. (Just like the main window)UIWindowLevelStatusBar
to have it cover everything. Set its hidden
property to NO.UIWindow
can be used to bring views on the screen that float on top of everything. Without creating a dummy controller just to embed that in a UIPopoverController
.Upvotes: 113
Reputation: 385600
A UIWindow
can float above other UI elements like the system keyboard.
To address your last paragraph: Make a UIWindow
with the same frame as your main window. Set its windowLevel
property to UIWindowLevelStatusBar
. Set its hidden
property to NO
.
Upvotes: 27