In my iPhone OS application I want (need) to watch for changes in the device orientation in order to rearrange certain portions of the screen. The approach I used was to use CGRect frame = [UIScreen mainScreen].applicationFrame
to get the screen size, and from there calculate the size and / or positioning of other controls (I also tried self.view.frame
).
All testing was done so far in Portrait mode, so I could focus on programming the main features and later on just do some adjustments for Landscape. And here enters the problem: In -(void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
I added some logging to check the sizes before proceeding, but apparently the values for Width and Height are "wrong" (I say "wrong" because at a first glance the values does not make sense to me).
Here's the output of some logging:
- Rotation: Landscape [w=300.000000, h=480.000000]
- Rotation: Portrait [w=320.000000, h=460.000000]
The values for "w" and "h" in Landscape seem inverted to me - I was expecting that w=480 and h=300.
What am I doing wrong? The code I used to debug is below.
-(void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
CGRect frame = [UIScreen mainScreen].applicationFrame;
CGSize size = frame.size;
NSLog(@"%@", [NSString stringWithFormat:@"Rotation: %s [w=%f, h=%f]",
UIInterfaceOrientationIsPortrait(self.interfaceOrientation) ? "Portrait" : "Landscape",
size.width, size.height]);
}
self.view.bounds
(considering that "self.view" is main main view, where other subviews to compose the app are added) I get the expected values. Now I get this behavior I remember of something they talked in the Standford iPhone Dev course in iTues U, but I'm not sure if it is related. Anyway, I still would like to have a more concrete opinion. – Rafael Steilself.view.frame
works fine if you have a navigation controller, but if you don't, it looks like you have to useself.view.bounds
. – Rob