views:

189

answers:

1

Hi,

I created an application with a TabBarController using IB who have 4 TabBarItems and so display 4 differents ViewControllers. To allow a landscape orientation I must add this code in all of my ViewController:


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
     return (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown ? NO : YES);
}

The problem is I don't want for example the secondViewController to autorotate, How can I do that? Because everytime I delete the code above in one of my ViewController, every ViewControllers not rotate anymore.

Thanks

A: 

Leave the code in there, but you'll want to do one of two things:

  1. Disable the non-rotatable tab when showing landscape view OR
  2. In the viewWillAppear or viewDidAppear for that tab, force rotation to portrait.

eg:

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES]
Ed Marty
the second method is not working, because shouldAutorotateToInterfaceOrientation work everytime I turn the device. can you tell me how can I do the 1st method? how to disable the non-rotatable tab?
ludo
The second method could work if you return NO when the non-rotatable view is visible. As for disabling the tab, use the view controller's tabBarItem property and set enabled to false. Something like nonRotatableController.tabBarItem.enabled = NO;
Ed Marty
not bad for the [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO] the problem is that all the others elements in the View rotate, the TabBar, the NavigationController and of course the View itself
ludo