Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XCode 4.5 / iOS6 : orientation issue with my iPad app in Landscape mode

I just opened my iPad project on XCode 4.5. My app is designed to run in Landscape mode. It works perfectly on previous versions of XCode. But on XCode 4.5, it is rotated of 90° (quarter turn) with a empty area on the right side of the screen (and my view has the correct size but goes out of the screen). It looks like this:

The view (red) rotated of 90° and going of the screen in landscape mode

I checked the following posts but didn't help:

orientation issue in ios6

ios6 Rotation issue from landscape to portrait mode

Set orientation to landscape mode in xcode 4.5 GM IOS 6

Anybody had this issue ?

Any help would be appreciated !

like image 277
Regis_AG Avatar asked Oct 03 '12 22:10

Regis_AG


2 Answers

Thanks everybody for your replies. I finally found a solution.

First, check that all your launch images have the correct orientation and correct size in the target summary menu (blue icon of your project => target => summary => scroll at the bottom) ; if the size or orientation is not correct, you get a warning on the launch image which is not set properly.

Up to now, I had a project with this structure (old XCode fashion):

  • AppDelegate.h and .m
  • RootViewController.h and .m
  • a MainWindow-Iphone.xib and MainWindow-iPad.xib (with the RootViewController linked in Interface Builder ; see the screenshot below with the yellow/brown icon (with a square inside) relative to the RootViewController)

Here below a screenshot of what it looked like:

My old project structure

And here is what was the code in the applicationDidFinishLaunching: method of my AppDelegate:

- (void)applicationDidFinishLaunching:(UIApplication *)application {  

     [window addSubview:[rootViewController view]];
     [window makeKeyAndVisible];

}

What I did is to be closer to the structure you get when you create an empty project with XCode 4.5. Consequently:

  1. I removed the MainWindow.xib and MainWindow-iPad.xib and now created my window programatically (clearer and better to make sure that it fits the size of any screen)
  2. I removed the "Main nib file base name" and "Main nib file base name (iPad)" keys which were defined in my Info.plist (and set to MainWindow.xib and MainWindow-iPad.xib)
  3. I added empty RootViewController_iPhone.xib and RootViewController_iPad.xib
  4. I changed the code in my applicationDidFinishLaunching method like this:

    - (void)applicationDidFinishLaunching:(UIApplication *)application {    
    
    NSLog(@"applicationDidFinishLaunching");
    
     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        self.rootViewController = [[RootViewController alloc] initWithNibName:@"RootViewController_iPhone" bundle:nil];
    } else {
        self.rootViewController = [[RootViewController alloc] initWithNibName:@"RootViewController_iPad" bundle:nil];
    }
    
    self.window.rootViewController = self.rootViewController;
    
    [self.window makeKeyAndVisible];
    

    }

And now, everything works fine ! Orientation is correct on iPad ! And it is much more clear than before :) I even didn't have to change the deprecated methods like

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

By the way, to make sure that all your views will be full screen (on iPhone 5) make sure that your views are set to the mode "Scale to fill" in Interface Builder and that "Autoresize subviews" is clicked. If some of your views do not scale to full screen, it is probably due to the order in which one you create your controllers/views (the superView sends a notification to its subviews only when it (the superView) is created). To solve this easily, simply add the following code in the - (void)viewDidLoad method:

CGRect screenBounds = [[UIScreen mainScreen] bounds];
    [self.view setFrame:CGRectMake(0,0,screenBounds.size.width,screenBounds.size.height)];

or use:

[self presentModalViewController:myViewController animated:TRUE];

instead of:

[self.view.superview addSubview:myViewController.view];

presentModalViewController indeed sends a resizing notification to the subviews.

Hope this will help !

like image 177
Regis_AG Avatar answered Nov 15 '22 22:11

Regis_AG


Make sure you are setting the window.rootViewController as well. I had the same issue, but this line fixed it for me:

MainViewController *mainView = [[MainViewController alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
window.rootViewController = mainView;
like image 38
Steve Y Avatar answered Nov 15 '22 23:11

Steve Y