I have a tabbar application. And the item of first tab is Navigation Controller.
Navigation controller has 4 items in his stack.
I want to provide rotation. But in tabbar application it’s the problem, that’s why I created my own tabbarcontroller and override the method:
@interface RotatingTabBarController : UITabBarController
@end
@implementation RotatingTabBarController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
if([self.selectedViewController isKindOfClass:[UINavigationController class]]){
BOOL f = [[(UINavigationController*)self.selectedViewController visibleViewController] shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
return f;
} else {
BOOL f = [self.selectedViewController shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
return f;
}
}
@end
After that if I provide in proper UIInterfaceOrientation support, my controllers will support autorotation. But without my custom RotatingTabBarController it’s seems impossible
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
The problem is:
When I push FirstViewController in navigation controller in shouldAutorotateToInterfaceOrientation of this viewcontroller I provide only portrait orientation,
but when I push SecondViewController (I provide there both portrait and landscape orientation), if current interface orientation of SecondViewController is landscape and I press back button (SecondViewController pop from stack and FirstViewController appears), the orientation of FirstViewController is landscape. But in shouldAutorotateToInterfaceOrientation method I provide only portrait orientation for him.
I used modal windows and hide back button in Landscape orientation. It solved the issue.