Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPad Landscape View frame size

When I use ViewController.View.frame.size.width and height in landscape mode, I am getting 768 and 1024 respectively where as I see 1024 and 768 from my Storyboard's "Size Inspector". Have anyone got any idea why this is happening?

like image 274
Murali Patteboyina Avatar asked Mar 13 '26 12:03

Murali Patteboyina


2 Answers

This is an oddity (bug?) in iOS. But I'd wager that so many people have done kludgy workarounds (e.g., inspect the device orientation and if landscape, flip the width and height), that I'm not sure if Apple dare fix this, for fear of breaking tons of apps.

As an example of the strange behavior, if you have a navigation controller, for example, you'll find that the frame.size is correct as you go from portrait to landscape mode, but in the absence of a navigation controller, it isn't. If you're just looking for the width and height, you can frequently grab bounds.size, instead, which appears to get updated properly, regardless.

like image 174
Rob Avatar answered Mar 16 '26 02:03

Rob


You cannot use the frame for a view's dimension. You have to use bounds. More info is here: My self.view has the wrong dimensions

like image 24
nonopolarity Avatar answered Mar 16 '26 01:03

nonopolarity