Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
472 views
in Technique[技术] by (71.8m points)

objective c - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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];
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...