I have a question about iOS 6 Orientation.Here is my file https://www.dropbox.com/s/f8q9tghdutge2nu/Orientations_iOS6.zip
In this sample code,I want to make the MasterViewController
only has a Portrait Orientation and the DetailViewController
has a Portrait Orientation,Landscape Orientation.
I know iOS 6 Orientation is controlled by top-most controller.
So I custom a UINavigationController(CustomNavigationController)
, set supportedInterfaceOrientations and shouldAutorotate in that class.
-(NSUInteger)supportedInterfaceOrientations{
if([[self topViewController] isKindOfClass:[DetailViewController class]]){
return UIInterfaceOrientationMaskAllButUpsideDown;
}else{
return UIInterfaceOrientationMaskPortrait;
}
}
-(BOOL)shouldAutorotate
{
return YES;
}
Everything is fine except when DetailViewController
at Landscape Orientation press back button,MasterViewController
will show the Landscape Orientation.
Can I let MasterViewController
always show Portrait Orientation and DetailViewController
can has many orientation?
thanks!
I made this work as you suggested in your comment on the question. The problem is that the default UINavigatonController does not use the value of the top view controller, so you need to override it by creating a base class and setting it in the Storyboard as the base class.
Below is the code that I use.
- (NSUInteger) supportedInterfaceOrientations {
return [self.topViewController supportedInterfaceOrientations];
}
I also have a base class for the rest of my View Controllers to default the behavior to use the Portrait orientation. I can override these methods for iOS 5 and 6 in any view controllers which support more than Portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
- (BOOL)shouldAutorotate {
return FALSE;
}