I’m working on an iphone app with a TabBarController as rootcontroller. And this rootcontroller is associated to Navigation Controllers (each one related to a specific Tab Bar button).
One on these navigation controllers shows some photos and thus I needed to enable Lanscape which obviously did not work until I added this code to all view controllers
- (BOOL)shouldAutorotateToInterfaceOrientation (UIInterfaceOrientation)toInterfaceOrientation
{
return YES;
}
However, now that all orientations are enabled in all views some views I didn’t want in landscape are showing very ugly 🙁
Any idea how to just leave the landscape orienation only on this photo view and disable it on all other views?
Consider showing the UIViewController that needs full reorientation capabilities modally.
That would be the common and in my humble opinion correct way to handle such situation.
To answer your subject in short: yes, it does have to return
YESif you want any of the tabbed viewControllers to allow reorientation. The same goes for viewControllers within the stack of yourUINavigationControllers. Hence the same goes for any combination of those.From Apple’s Technical Note on that subject:
In case using a modally presented view controller is no option for you – here comes another way…
There is also a solution possible that seems a little “hacky” but worked for me in the past. I will draft it in a very very “hacky” way to simplify the answer.
Within the shouldAutorotateToInterfaceOrientation:toInterfaceOrientation implementation of all of your viewControllers, return a global value. Change that global value according to the needs of the currently displayed viewController. Even though it is said that a viewController is only asked once, this common rumor has proven untrue for my. So here comes the super hack;
All view controllers within your navigation stack should implement the shouldAutorotate-method like this:
Now, somewhere in your app, you should declare and instantiate that global flag – you could place this ugly global flag within your app-delegate implementation, directly below the imports and above the @implementation block:
Within all viewControllers that are supposed to be shown in portrait mode only, set that flag towards NO – e.g. within viewWillAppear;
Within the viewController/s that are supposed to be shown in any orientation, set that flag towards YES – again within viewWillAppear;
That way, whenever the entire navigation stack is asked for its orientation capabilities, the proper answer will be given. From my experience, the entire stack is asked, over and over again and answers are not cached, hence my hack worked whenever I needed it. Still, the rumor seems to be widespread that those answers are somehow cached and therefor that rumor might be valid in certain cases – hence I shall not be held responsible if this does not work for you (or even down voted 😀 )