Can
Can

Reputation: 556

is there anyway to change easly Interface Orientation?

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.

Upvotes: 1

Views: 369

Answers (1)

sergio
sergio

Reputation: 69027

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).

Upvotes: 1

Related Questions