Question

I've always seen references to an app's 'window', and I see that AppDelegates usually have a UIWindow property called 'window'. So I'm just wondering how to perceive this UIWindow object. I see that it's a subclass of UIView, so I guess technically it's a View right? So would it be safe to say it's like the Superview of an entire app? Also, when and why might I ever refer to it? What value does it add?

I know there are a lot of questions in there but just some overall context on UIWindow would be nice.

Was it helpful?

Solution

You might want to check out the About Windows and Views section in the View Programming Guide for iOS.

In iOS, you use windows and views to present your application’s content on the screen. Windows do not have any visible content themselves but provide a basic container for your application’s views. Views define a portion of a window that you want to fill with some content. For example, you might have views that display images, text, shapes, or some combination thereof. You can also use views to organize and manage other views.

Also note that an iOS application usually only has one window. An exception would be, if an app displays content on an external screen.

OTHER TIPS

UIWindow
The presentation of one or more views on a screen is coordinated by UIWindow object. In iOS application usually only has one window. while View multiple. Windows and Views both are used for present your application’s content on the screen. Windows provide a basic container for your application’s views but not have any visible content. The view is a portion of a window where you can fill with some content.For example, you might have views that display images, text.

ProblemStucks

Window is like a topmost UI container for any iOS application. It sits above all of your views and viewControllers.

Ask me why it is needed, And I say it makes the UI structure more clear in terms of view hierarchy and event handling. For example any user event, when not handled by the innermost view, goes up the view hierarchy eventually to the window object if no other view in the hierarchy handles it.

Another example is the rootViewController of a window which handles view-specific details of the application.

There will be mostly one window for an application. But I have worked on an app which used a shared framework for user authentication. And there, we had a separate window specific to that auth framework. Why separate window you ask, and here I go again, there are 2 important use cases,

  1. As I mentioned it was a shared auth framework. Hence different apps could use the same framework for user authentication which uses its own window for login screen etc.
  2. There was a session timeout after which, a login screen had to pop up regardless of what user is currently doing on the screen. This can get really tricky if we don't use a separate window.

I hope you can understand essence of a window after reading these examples.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top