Note that there are some explanatory texts on larger screens.

plurals
  1. PO"Incorrect" frame / window size after re-orientation in iPhone
    text
    copied!<p>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 <code>CGRect frame = [UIScreen mainScreen].applicationFrame</code> to get the screen size, and from there calculate the size and / or positioning of other controls (I also tried <code>self.view.frame</code>).</p> <p>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 <code>-(void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation</code> 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). </p> <p>Here's the output of some logging:</p> <ul> <li>Rotation: Landscape [w=300.000000, h=480.000000]</li> <li>Rotation: Portrait [w=320.000000, h=460.000000]</li> </ul> <p>The values for "w" and "h" in Landscape seem inverted to me - I was expecting that w=480 and h=300. </p> <p>What am I doing wrong? The code I used to debug is below. </p> <pre><code>-(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]); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload