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

让人想犯罪 __ 提交于 2019-12-13 20:07:35

问题


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.



来源:https://stackoverflow.com/questions/10743740/on-ios-can-we-get-to-the-main-uiwindow-object-from-the-uiscreen-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!