0

I have view that is displayed in landscape mode. I want to modally display a new view controller with a portrait orientation (so that is looks like it’s sliding in from the right). Currently, when I execute the code below, it modally displays the new view controller in the same landscape orientation that the calling view controller has. How can I modally display a new view controller with a portrait orientation, from a view controller that has a landscape orientation?

Here’s my existing code...

//This code is called from the landscape view controller

- (void)showPortraitViewControllerButtonTapped

{

  MyViewController *vc = [MyViewController new];

  UINaviationViewController *navVC = [[UINavigationViewController alloc] initWithRootViewController:vc];

  [self presentViewController:navVC animated:YES completion:nil];
}

//Code inside the view controller that I want to modally display in portrait orientation

@implementation MyViewController

(NSUInteger)supportedInterfaceOrientations 
{

   return UIInterfaceOrientationMaskPortrait;

}

@end

Thanks in adavnce for your wisdom!

BeachRunnerFred
  • 18,070
  • 35
  • 139
  • 238
  • A bunch of hints [here](http://stackoverflow.com/questions/12520030/how-to-force-a-uiviewcontroller-to-portait-orientation-in-ios-6). – Mat Jul 08 '14 at 17:26
  • There is also a storyboard solution here:http://stackoverflow.com/questions/32255151/tabbarcontroller-rotation-problems/32390717#32390717 – SwiftArchitect Jan 31 '16 at 01:28

1 Answers1

0

Instead of forcing orientation over a controller, since all you are interested in is the transition, you should control the transition itself:

[self.navigationController.view.layer addAnimation:({
    CATransition *transition = [CATransition animation];
    transition.type = kCATransitionMoveIn;
    transition.subtype = kCATransitionFromTop;

    transition;
}) forKey:@"SlideFromRightInLandscapeLeft"];
[self.navigationController pushViewController:navVC animated:NO];

Note that instead of -presentViewController, this uses -pushViewController. Close your navVC like so:

[self.navigationController popViewControllerAnimated:YES];
SwiftArchitect
  • 47,376
  • 28
  • 140
  • 179