Benefits, problems, examples of adding another UIWindow to an iOS application?

I recently wondered that an iOS application has only one UIWindow . It doesn't seem like a problem to create another UIWindow and place it on the screen.

My question is fuzzy, but I'm interested in:

  • What can I achieve with a second UIWindow that cannot be done in other ways?
  • What could be wrong when using multiple instances of UIWindow ?
  • I have seen that people use 2nd UIWindow to display popover, like representations on iPhone. Is this a good way to do this? What for? Why not?
  • Are there any other examples in which it makes sense to have another UIWindow ?

This is not something that I am missing out on. I never felt the need to create another instance of UIWindow , but perhaps this will allow me to do amazing things that I donโ€™t know about !:-)

I hope this helps me solve this problem: I need to add a โ€œcoverโ€ over what is currently displayed. It should also work if there is already one or more modal controllers. If I add a UIView to the root controller view, the modal controllers will sit on top, just like the popover controllers. If I present the view of the cover in a modular way, and there is already a modal controller, only part of the screen is covered.

+82
objective-c cocoa-touch uikit uiwindow
Nov 22 '11 at 19:11
source share
2 answers

A UIWindow can float over other interface elements, such as a system keyboard.

To refer to your last paragraph: Make UIWindow with the same frame as your main window. Set the windowLevel property to UIWindowLevelStatusBar . Set the hidden property to NO .

+19
Nov 22 '11 at 19:49
source share

Starting with Rob's answer, I played a little and would like to write a few notes for others trying to get information on this topic:

  • It is not a problem to add another UIWindow . Just create one and makeKeyAndVisible . Done.
  • Remove it by making another window visible, then release the one you no longer need.
  • The window, which is the "key", receives all the keyboard input.
  • UIWindow covers everything, even modals, popovers, etc. Brilliant!
  • UIWindow is always a portrait implicitly. It does not spin. You will need to add the controller as the new root window controller and enable its rotation. (As in the main window)
  • The window level determines how high it is displayed. Set it to a UIWindowLevelStatusBar so that it covers everything. Set the hidden property to NO.
  • The 2nd UIWindow can be used to display views on a screen that floats on top of everything. Without creating a dummy controller to insert it into the UIPopoverController .
  • This can be especially useful on iPhones where there is no popover controller, but where you can imitate something like this.
  • And yes, that, of course, solved my problem: if the application resigns, add a cover window on top of what is currently displayed to prevent a screenshot from starting up your application.
+93
Nov 23 '11 at 9:20
source share



All Articles