I have a tab based application in which one tab is available in both portrait and landscape mode, all the others are only available in portrait.
I am checking against the button selected to allow rotation in shouldAutorotateToInterfaceOrientation: or not, but when I am in landscape mode, when I select a different tab I need to load that view controller but also force my application into the normal portrait layout mode.
There doesn't seem to be a clear and preferred was to do this, I tried setting the status bar orientation but the status bar was the only visual element to move.
Any tips and examples would be great, thanks.
I think if you just use the following code and it should work well.
}
I was able to do this, but I'm warning you now, it's a hack.
First, I created a category for UITabBarController called
UITabBarController+SelectiveRotation
:This allows the TabBar to rotate freely whenever the selected tab allows an orientation. Make sure you import this file wherever you're creating your
UITabBarController
(probably in your application delegate).Then, I had my AppDelegate make itself the delegate of the tab bar, and I implemented this method:
This second bit of code forces the tab bar to rotate to an acceptable orientation when the tab changes. For instance, if you go to the tab that can rotate, and go to landscape, then go to a tab that only supports portrait, it'll force the orientation change to portrait. On iOS 4.3 and earlier, going back to the rotated tab will present it in the orientation you left it in. I couldn't figure out a way around that.
I did all this because it was a client requirement, but I don't think this is actually a very usable design. I don't find too many visual tweaks to be disorienting, but forcing the device to rotate by this method is very jarring because it's instantaneous. You might want to try it out and see how you feel about it.