This is just a test application, There is only a AppDelegate class to create all I did was create a Window based app, set the supported orientations to only the landscape in the info.plist, and then add the following code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[application setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft];
// Override point for customization after application launch.
UIAlertView *test = [[UIAlertView alloc] initWithTitle:@"hu" message:@"hui" delegate:nil cancelButtonTitle:@"hi" otherButtonTitles:nil];
[test show];
[window makeKeyAndVisible];
NSLog(@"win %f - %f", window.bounds.size.width, window.bounds.size.height);
return YES;
}
Without the first line, which sets the status bar orientation, the alert view appears in portrait even though the rest of the interface is in landscape left.
Anyway the Log still gives this:
win 768.000000 - 1024.000000
This is the wrong way round (and thus when I add subviews in my real app the frames are not correct)
Apple seems to have really mucked up on the interface rotation, because I’ve had nothing but problems, I don’t remember any of this happening on the iPhone, so please can someone tell me how to fix this.
I’ll give 500 reputation (that’s all but 10 of my reputation) to the person who can at least explain why this happens and hopefully provide a solution.
I think the “Launching in Landscape Mode” of the iOS Application Programming Guide mostly explains what is happening with your test application:
In terms of your test application, the key part is the last section. You do not have a view controller, so you are entirely responsible for setting up the UI in the orientation you want. That is why you have to set the status bar orientation manually.
I read the first paragraph as saying that iOS apps always launch in portrait mode and then the root view controller rotates its view to match the device orientation immediately and without animation once it is added to the window. That means the UIWindow itself does not rotate so its dimensions will always be in terms of a portrait orientation (as tadej5553 has said). In addition, the frames of all of the UIWindow subviews will also be in terms of a portrait orientation (since the frame is always defined in the parent view’s coordinates). So, no matter how you rotate the device, the root view controller’s frame will always be in terms of a portrait orientation. However, since a view’s bounds property is defined in terms of its own coordinates, that height and width should reflect the current orientation of the view.
It is not clear what you are trying to accomplish with your real app, but the recommended practice is to lay out your views for portrait orientation and then set their autoresizing properties to handle the automatic rotation (whether it occur immediately after app launch or later).