I have an iOS 6 iPad app where most of ViewControllers have their Navigation Controller. In all these views I want the orientation to be only landscape, which works just fine. There is one View Controller though which does not have a Navigation Controller - I just open its view on top of Navigation Controller's top View Controller, but it's not a modal. I do want the user to be able to change screen's orientation on that View Controller, but keep landscape on all the rest of them. This is what I do:
Navigation Controller's subclass:
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
-(BOOL)shouldAutorotate {
return UIInterfaceOrientationIsLandscape(self.interfaceOrientation);
}
And here are the same methods for the particular View Controller that I want to have both landscape and portrait:
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
- (BOOL)shouldAutorotate {
return YES;
}
Since this View Controller doesn't have a Navigation Controller I was sure that this would solve the issue. However for some reason I'm still not able to flip the screen in this View Controller. Here is the way I show that View Controller - maybe this is the reason behind this:
UIWindow *window = [[UIApplication sharedApplication].windows objectAtIndex:0];
[[window.subviews objectAtIndex:0] addSubview:previewView];
In fact , the way you show this special view controller make your view unable to change orientation , because when device change orientation , it ask your key window's rootController whether it can orientate or not , and in your situation , you return landscape so your window only support landscape mode.
So maybe you should present it from your navigationController without animation . than implement - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
in your special view controller.
Further reading: Understand ViewController Orientation