How to handle auto rotation in UITabBarViewController based application

For TabView based application, there is many case that some of the view can be in landscape mode while other can't. In some cases, it is even complicated that one of the view in tab bar is navigation based and the view can only be in landscape mode after it is pushed to some view.

To handle this, it is very simple. Subclass you UITabBarViewController and overload this function:


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}

Then the tab bar view controller will ask the current selected view controller for the orientation status. If the selected view controller is an navigation view controller, it will ask the current pushed view controller. So the orientation will be displayed correctly according the shouldAutorotateToInterfaceOrientation function of each view controller inside.

Note that this can only be good for application that complied for OS 3.0 or later. It is because that in OS 2.x, the auto rotation is badly implemented.