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

2019-09-16 15:39发布

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条回答
淡お忘
2楼-- · 2019-09-16 16:26

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.

查看更多
趁早两清
3楼-- · 2019-09-16 16:29

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.

查看更多
登录 后发表回答