I am currently working on a project in which we have a tab bar controller with 4 tabs and where each tab has a navigation controller. On each of these navigation controllers, several controllers are pressed on it.
I read a lot of posts here and other places, and we currently do the following:
Subclass UITabbarcontroller
- (BOOL)shouldAutorotate { return [[[self.viewControllers objectAtIndex:self.selectedIndex]topViewController] shouldAutorotate]; } - (NSUInteger) supportedInterfaceOrientations { return [[[self.viewControllers objectAtIndex:self.selectedIndex]topViewController]supportedInterfaceOrientations]; } - (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{ return [[[self.viewControllers objectAtIndex:self.selectedIndex]topViewController] shouldAutorotateToInterfaceOrientation:toInterfaceOrientation]; }
This work is great if we specify the following in each of our view controllers:
- (NSUInteger) supportedInterfaceOrientations{ return UIInterfaceOrientationMaskPortrait; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{ return YES; }
This will block it until Portrait, as expected.
But now a real problem arises! If in our view the dispatcher on one of the tabs indicates that it should rotate into the landscape, it works fine, but when we change the tab, it is still in the landscape, which we don’t want!
So, to summarize, does anyone have a solution, how do you block almost all views on a given orientation, and can change the tabs where they are in the orientation you specified (here is a portrait)?
I also read this post. IOS 6 UITabBarController supported orientation with the current UINavigation controller , but as one comment noted, “it almost works for me. I am already in the landscape when I switch tabs to portrait only because it is still located in the landscape. A rotating portrait captures it and it won’t turn back to the landscape, but I still need it to be in the portrait when it first loads up ", which is almost the same here ..