Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force Landscape ViewController in iOS 7

I have more than ten ViewControllers in portrait mode, but I need to force a single one in Landscape mode regardless of the device´s orientation.

like image 491
Fede Cugliandolo Avatar asked Dec 15 '22 00:12

Fede Cugliandolo


1 Answers

Here is the solution:

1) Embed the LandscapeViewController in a subclassed NavigationController and connect it from your PortraitViewController using a modal segue.

LandscapeViewController embedded into a new LandscapeNavigationController

2) Subclass UINavigationController

LandscapeNavigationController.m

-(BOOL)shouldAutorotate
{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscapeLeft;
}

3) Don't forget to dismiss your modal VC (in this case from my Bar Buttom Item Action)

- (IBAction)goBack:(id)sender
{
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
like image 100
Fede Cugliandolo Avatar answered Jan 01 '23 21:01

Fede Cugliandolo