1
votes

My problem is the following: I want to only allow Portrait orientation on all my ViewControllers except 1 ViewController which is supposed to allow both Portrait and landscapeLeft/Right. I have now spent almost 2 days into how to set orientation in IOS for different slides/ViewControllers. After some searching I found this thread here at stack: UITabBarController Rotation Issues in ios 6

I followed Kunani's example in that thread which I will post here to save all readers some time:

Zack, I ran into this same issue. It's because you have your viewController embedded inside of a TabBar Controller or UINavigationController and the calls to these methods are happening inside those instead of your normal View (Changed in iOS6). I ran into this issue because I was presenting a viewController embedded inside a UINavigationController on all my modal views that had Navigation to different views (Signup Process, Login, etc). My simple fix was to create a CATEGORY for UINavigationController that includes these two methods. I have shouldAutorotate returning NO anyway because I don't want my modal views rotating. Your fix may be this simple, give it a try. Hope it helps. I created a category and named it autoRotate and selected theUINavigationController option. The M+H file are below.

#import "UINavigationController+autoRotate.h"

@implementation UINavigationController (autoRotate)

-(BOOL)shouldAutorotate {
return NO;
}

- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}

@end

... and the category .h:

 #import <UIKit/UIKit.h>

 @interface UINavigationController (autoRotate)

-(BOOL)shouldAutorotate;
- (NSUInteger)supportedInterfaceOrientations;

@end

I did what he said and tried to set category for my UITabBarController which worked, all classes connected to the tabBar now only allows orientationPortrait. But if you look at the following Picture

enter image description here

(screenshot from my project) there is a class in the middle of the StoryBoard called ShowTaskView. This class is connected to most classes (which are directly connected to the UITabBarController) via a UINavigationController. Even if I set UITabBarController to only allow Portrait also ShowTaskView seems to get affected by that rule and I can not make it to rotate. The scheme in my project can also be described as this:

TabBarController ----> UINavigationController -------> class X ----------> class ShowTaskView

What can I do from here if I want my classes connected to tabBarController only to allow orientationPortrait and the rest of the classes allow both portrait and landscape based on how my project is built? I am very frustrated at this issue since it is so damn hard to solve :/

Regards

1
Please refer my answer, i think it solve your issue stackoverflow.com/questions/12522903/…Võ Huy Hưng

1 Answers

0
votes

please refer to my answer in similar thread: Navigation controller stack in landscape mode, but modally presented view controller view always in portrait frame size

iOS6 controls rotation by the navigation stacks, so wrap your rotatable view into separate navigation controller to be able to control it there.