tags:

views:

517

answers:

6

What's really going on behind the scene when you set the phone's orientation to landscape mode? When I traced out main screen's bounds and any subview's bounds, the width and height is still 320x480, rather than 480x320.

Any idea why?

A: 

Are you checking the bounds property or the frame property? Certain controls, especially UIViews that fill up the screen, appear to maintain the same frame in any orientation; I think that AppKit sets their transform property to rotate their contents.

You will probably find that the bounds property has the value that you expect it most of the time, but that the frame property does not.

Leo
I checked both bounds and frame, they both come out reflecting the portrait mode information (i.e. 320x480)
Boon
A: 

Yes, the frame and bounds stay the same, you should check the ViewController's interfaceOrientation property, and treat the width and the height accordingly, if your layout depends specifically on these.

luvieere
A: 

Did you ever find an answer to this? I've got the same issue with an iPad application at the moment. I "solved" it by querying the views interfaceOrientation and if it is either UIDeviceOrientationPortrait or UIDeviceOrientationPortraitUpsideDown then I manually set the frame of my sublayer in the view (which is a CAGradientLayer).

rickerbh
A: 

I have the same issue as well..

In the .plist I set orientation to landscape (home button right)

and then I set:

- (void)applicationDidFinishLaunching:(UIApplication *)application
{
    //size of the application
    rect = [[UIScreen mainScreen] bounds];

    NSLog(@"RECT x:%f y:%f w:%f h:%f",
        rect.origin.x,
        rect.origin.y,
        rect.size.width,
        rect.size.height);

}

In the Log I get "RECT x:0 y:0 w:320 h:480"

Since it is in landscape I believe it should be 480x320 not the other way around.

dkk
+1  A: 

This is a large topic, but I'll add what amounts to 0.02; comments are constrained to changes between portrait and landscape; i.e., not things like upside down, face up, face down, and unknown.

  1. If a view is not listening for orientation changes then the frame and bounds will remain the same regardless of orientation.

  2. If a view has registered to listen for orientation changes then the bounds may change; i.e., in landscape whole screen frame is <320,480> while bounds is <480,320>. This assumes:

    a. you are either using a shouldAutorotateToInterfaceOrientation callback with appropriate YES return values, or

    b. explicitly registering with the notification center to listen to UIDeviceOrientationDidChangeNotification.

  3. Approach 2a will hold true only for views belonging to the app window's root view controller; that is, the view controller whose view was added first. Approach 2b can be used in conjunction with affine transforms and manual bounds changes to get proper orientation layout for views not governed by autorotation.

jstevenco
A: 

I found that if you are not using an UINavigationController you can get problems with your view not being given the correct view and frame bounds.

I was directly adding views to the UIWindow and had exactly this problem. But when I sandwiched a UINavigationController between the UIWindow and my UIViews the problem went away.

Hope that helps

Neonplay