0

When my device is in landscape mode and I modally present a view controller, this is always displayed in portrait mode, which is what I want.

However, I don't understand why other views (modally presented) are always displayed in landscape mode instead (if the current orientation of the device is landscape). The code I use is the same for all my view controllers, and the xib file orientation property is always Portrait.

This is how I push the view controller which works (it is never displayed in landscape mode):

 - (IBAction)showImport:(id)sender
    {
        CMImportExportViewControlleriPhone *importController = [[CMImportExportViewControlleriPhone alloc] initWithNibName:@"Import-Export-iPhone" bundle:nil];
        [importController setLayoutViewController:self];
        //[importController setDelegate:self];
        [self presentModalViewController:importController animated:YES];
        [importController release];
    }

thanks

aneuryzm
  • 63,052
  • 100
  • 273
  • 488

1 Answers1

0

If this is initial view controller and you have settings in plist file to start application in portrait mode then it would display in portrait mode doesn;t matter what is your device orientation. When you put your device in landscap mode and present new view controller, it will be landscap as it follows the status bar orientation! Before presenting new view controller try reseting status bar to portrait mode and then present new view controller. It will be presented in portrait mode! I had this similar issue in iOS 6.0.

Paresh Masani
  • 7,474
  • 12
  • 73
  • 139
  • It is not the initial controller, and I'm setting the status bar orientation in the code above, but still it is always portrait. I've tried to set the status bar orientation before to present the other view controllers, but still they are displayed in landscape mode. – aneuryzm Oct 02 '12 at 08:51
  • That's strange! Are you using iOS 6.0? If you want only portrait modes then you can just lock your overall app to use portrait mode only! – Paresh Masani Oct 02 '12 at 08:55
  • Yes, iOS 6.0. No, the challenge here is to present a modal screen in portrait mode, when the device (and the current view) is in landscape mode. – aneuryzm Oct 02 '12 at 13:00
  • Hang on...In iOS 6.0 your app delegate extends UIResponder not UIApplication. I am sure you will be using [[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationPortrait animated:NO]; to set the status bar orientation but this wouldn't work anymore. Is your status bar actually rotating? – Paresh Masani Oct 02 '12 at 13:06
  • I fixed this. You will have to include the methods given in http://stackoverflow.com/questions/12691120/set-status-bar-orientation-in-ios-6-0/ in each view controller's implementation. I hope you are using storyboard. If you don't use storyboard then just create base class and put these methods in the base class and inherit base class from each controllers that you want to stay in portrait mode. Rest are still rotates in landscape but these viewcontroller would always stay in portrait even you rotate the device! Interesting fix :-) – Paresh Masani Oct 02 '12 at 13:38