[UIScreen mainScreen] .bounds vs [UIApplcation sharedApplication] .keyWindow.bounds?

I have an idea that I want to cover the entire screen. And I want his frame to cover the entire screen. Looking at the stack overflow, I found these two different ways to set the view frame:

[UIScreen mainScreen].bounds [UIApplcation sharedApplication].keyWindow.bounds 

It seems to me that they return the same values ​​always, or at least in several test cases that I tried.

I am currently using UIScreen , but am curious to know the difference between these calls? Will there be cases when they return different values?

+4
source share
1 answer

The methods are slightly different. [UIScreen mainScreen] returns a UIScreen device object, the boundaries of this will always be the screen size of the devices. [UIApplication sharedApplication].keyWindow returns the current UIWindow key for the application, which may not be the full screen size of the devices.

Another obvious case where they may differ is that the device is connected to multiple screens. In this case, [UIScreen mainScreen].bounds will always return the screen size of the device, but the key window may be on one of the other screens, and it will have a completely different size, depending on which screen it is attached to.

+12
source

Source: https://habr.com/ru/post/1489646/


All Articles