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

Categories

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

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

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...