-->

On iOS, can we get to the main UIWindow object fro

2019-09-16 15:44发布

问题:

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)

回答1:

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.



回答2:

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.