On iOS, can we get to the main UIWindow object from the UIScreen object?

1k views Asked by At

Say, if we already have aScreen that points to the main screen, by

UIScreen *aScreen = [UIScreen mainScreen];

can we get to the main UIWindow object from this UIScreen object? (do they have any connection at all? That is, instead of using [UIApplication sharedApplication].keyWindow)

2

There are 2 answers

0
djromero On BEST ANSWER

No.

The application has a list of windows, usually just one. Each window has a screen property that indicates where it's currently located. The screen object holds information about the physical device.

It seems inspired on OSX NSScreen, there is no a list of windows per screen. Each app has windows, each window knows in which screen is located.

0
strings42 On

A UIWindow knows which screen it's assigned to, but a UIScreen doesn't know what UIWindows are using it. That's why the standard pattern is to save the main window as a property of the ApplicationDelegate, so you'll have a reference to it.