I find that UIScreen.main.bounds are really hard to grasp. They are inconsistent, and their values doesn't seem to reflect the device. They are not static but change when the device is rotated which is really confusing, and often the values are the opposit of what you would expect.
For example:
In portrait mode
print("Portrait", " width: ", UIScreen.main.bounds.size.width, " height: ", UIScreen.main.bounds.size.height)
gives
Portrait width: 1024.0 height: 768.0
Correct me if I'm wrong but shouldn't the width be less then the hight on an iPad pro simulator?
Landscape mode is also confusing.
print("landscape", " width: ", UIScreen.main.bounds.size.width, " height: ", UIScreen.main.bounds.size.height)
gives
landscape width: 768.0 height: 1024.0
This means that 1. UIScreen.main.bounds is not static but change with screen orientation and 2. The width is still less then the hight.
I don't get it. Is there a way to get a static representation of the screen size and one that makes sense?
EDIT
Another strange phenomena is that UIScreen.main.bounds.height gives 1024 if I print it in viewDidLoad. But if I flip orientation and then back to the way it was, then restart the simulator the same print gives 768. Why oh why. This is so weird.
Have you consulted the docs on
UIScreen.bounds?And then below in the See Also section there's a link to
nativeBounds. Its doc states:There you have the static bounds you're looking for.