1

I have MainWindow.xib file and I try to desing a second .xib file which is MainWindowLandscape.xib. I have many .xib file and I design them separately for Portrait and Landscape.

I want to assign them in MainWindow.xib and MainWindowLandscape.xib ( UITabbarController based ), I mean I will assign portrait views in MainWindow.xib, and landscape views in MainWindowLandscape.xib. Is it possible or what is the easiest way?

All views ( portrait and landscape ) do same thing in each other. Only UI will be change.

Thanks a lot.

Can
  • 536
  • 2
  • 7
  • 22

1 Answers1

1

You can do that by overriding

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation

in the view controllers associated to the two xib files.

Concretely, in case you want to force the orientation to always be portrait, do:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation      {
    if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation))
       return YES;
    return NO;
}

When you want to force your view controller to always show in landscape:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation      { 
    if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation))
       return YES;
    return NO;
}

Once you do this, you have to keep in mind that controllers will auto rotate only if they meet the conditions for it to happen. Specifically, for tab bar controllers, all internal controllers must support the given orientation (i.e., they should implement shouldAutorotateToInterfaceOrientation like above).

sergio
  • 68,819
  • 11
  • 102
  • 123
  • I'm not sure if this is what you're suggesting, but the documentation states that the result of `-shouldAutorotateToInterfaceOrientation:` should *not* change dynamically. – jtbandes Aug 16 '11 at 16:52
  • @jtbandes: it seems to me that my `shouldAutorotateToInterfaceOrientation` implementations are pretty static. Each implementation is specific to a controller type, if it was not clear... – sergio Aug 16 '11 at 16:57
  • Ah ok. I just misinterpreted "when you want to force landscape". – jtbandes Aug 16 '11 at 17:10
  • yes I have added this block to my project all views but it doesn't work ? is there any tutorial that you know which has UITabbarController and UINavigationController? – Can Aug 16 '11 at 17:22
  • Don't know of any tutorial, but have a look at this:http://stackoverflow.com/questions/2868132/shouldautorotatetointerfaceorientation-wont-work -- if you need more help, you could post some code... – sergio Aug 16 '11 at 17:35