Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible that an iOS application can have more than one window?

Tags:

ios

uiwindow

I have been asked this question many times in the interview searched every where didn't get any proper answer.So finally posting this question here.

like image 648
Bharat Bhushan Avatar asked Oct 27 '17 12:10

Bharat Bhushan


2 Answers

You may go through this.

Yes, you can have multiple windows. A key window is the one who receives the user input.

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:

  1. It is not a problem at all to add another UIWindow. Just create one and makeKeyAndVisible. Done.
  2. Remove it by making another window visible, then release the one you don't need anymore.
  3. The window that is "key" receives all the keyboard input.
  4. UIWindow covers everything, even modals, popovers, etc. Brilliant!
  5. UIWindow is always in portrait implicitly. It does not rotate.
  6. You'll have to add a controller to the new window's root controller and let that handle rotation.
  7. (Just like the main window) The window's level determines how "high" it gets displayed. Set it to UIWindowLevelStatusBar to have it cover everything.
  8. Set its hidden property to NO. A 2nd 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.
  9. It can be especially useful for iPhone where there is no popover controller but where you might want to mimic something like it.
  10. And yes, it solved, of course, my problem: if the app resigns activation, add a cover window over whatever is currently shown to prevent iOS from taking a screenshot of your app's current content.
like image 192
Karthik Kumar Avatar answered Nov 19 '22 18:11

Karthik Kumar


Generally one application require only 1 UIWindow, but still there may be some scenarios where you need to use multiple UIWindow in one application.

For example, you wish to show a view on the top of system AlertViews, or can the default Keyboard.

UIWindows are the special UIViews, for which their display order is controlled by .windowLevel property.

You don't need to add a new UIWindow as a subview of any of view. You can simply create a new UIWindow and call either window setHidden:NO or window makeKeyAndVisible depend on the level, you have given to it.

There are three default window enum levels defined:

  • UIWindowLevelNormal
  • UIWindowLevelStatusBar
  • UIWindowLevelAlert
like image 34
nilam_mande Avatar answered Nov 19 '22 17:11

nilam_mande