Question

My application is quite simple, but I have some problems when it starts. I setted in the Info.plist to be landscaped, but it seems to ignore the order. In fact, when the app is loading the Simulator is landscaped, but then it returns in portrait mode.

This is the hierarchy of the views and controllers:

  • MainViewController (extends UITabBarController just to override shouldAutorotateToInterfaceOrientation:)
    • Three extended UITableViewControllers as tabs (also those have the shouldAutorotateToInterfaceOrientation correctly setted up).

If I kinda force the orientation of the device to Landscape with:

[[UIDevice currentDevice] setOrientation: UIInterfaceOrientationLandscapeRight];

Then for an instant the Simulator flashes in portrait mode, and then it goes landscaped. The problem is that in this way, the auto-rotation animations gets started, which is something I cannot tollerate. I just want a fixed, landscaped application.

Any clues? Am I missing something?

Was it helpful?

Solution

Try the following. Not sure why it does not work for you

1) set the key UIInterfaceOrientation
to UIInterfaceOrientationLandscapeRight in your .plist file

2) override your UITabBarController shouldAutorotateToInterfaceOrientation() method; in the following the code only deals with tab zero and one, and only with one controller: if you have a navigation controller and you want to control different controllers that may be on the stack, you have to modify the code accordingly

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    BOOL tabZeroController = [[[self.viewControllers objectAtIndex:0] visibleViewController] isKindOfClass:[YourTabZeroTableViewController class]];

    BOOL tabOneController = [[[self.viewControllers objectAtIndex:1] visibleViewController] isKindOfClass:[YourTabOneTableViewController class]];


    if(self.selectedIndex == 0 && tabZeroController)
        return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);

    if(self.selectedIndex == 1 && tabOneController)
        return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);

    return NO;

}

2) setting

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

in your delegate's applicationDidFinishLaunching() method is only required for the simulator, not on a device

3) add the following shouldAutorotateToInterfaceOrientation(method) in your controllers

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{
   return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

4) run the app on your device and verify that it works properly by using the Hardware menu item Rotate Left and Rotate Right. You should see the display in landscape-mode.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top