Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On iOS, why does height of a view's frame remain almost the same after rotation?

In ViewController.m, on an iPad, if we print out the view's frame height in a tap event handler:

NSLog(@"Height of main view is %f", self.view.frame.size.height);

then in Portrait mode, the value is 1004 (20 pixel for device status line, so 1024 - 20 = 1004), and if the device is rotated to Landscape mode, I expected it to be about 768 or 748, but the value printed is actually 1024. (update: if the app is started in Landscape mode, then without rotation, it is also printed as 1024). Why would that be, and is there a rule of thumb to expect getting the value of 748 or 768? (Is there more than one way to get that?)

like image 312
Jeremy L Avatar asked May 23 '12 05:05

Jeremy L


1 Answers

In Apple's documents, about UIView's frame:

Warning: If the transform property is not the identity transform, the value of this property is undefined and therefore should be ignored.

So you should use bounds property.

like image 51
xzgyb Avatar answered Oct 21 '22 18:10

xzgyb