Problem pushViewController from Landscape to Portrait

后端 未结 3 1944
青春惊慌失措
青春惊慌失措 2020-12-16 06:39

I am trying to go from a viewcontroller that supports landscape (while in landscape mode), to one that explicitly doesn\'t (and shouldn\'t) support landscape. I\'m doing thi

相关标签:
3条回答
  • 2020-12-16 06:54

    The answer by Sahil above is deprecated since iOS 6.0. However, the following seems to do the same trick:

    UIViewController *viewController = [[UIViewController alloc] init];
    [self presentViewController:viewController animated:NO completion:nil];
    [self dismissViewControllerAnimated:NO completion:nil];
    [viewController release];
    
    0 讨论(0)
  • 2020-12-16 07:10

    I found a way to force portrait. It's a bit a hack, but here it is. In the -(void)viewDidLoad of the viewController that you want to force portrait for do the following:

    UIViewController *viewController = [[UIViewController alloc] init];
    [self presentModalViewController:viewController animated:NO];
    [self dismissModalViewControllerAnimated:NO];
    [viewController release];
    

    This basically forces portrait, by presenting a controller (which only supports portrait by default).

    0 讨论(0)
  • 2020-12-16 07:16

    You will need to present your new view controller modally. If your view controller exists within a navigation controller the orientation of all view controllers in the nav stack is implied by the root view controller in the stack. Whatever your root view controller in the nav stack returns from shouldAutoRotateToInterfaceOrientation is then used for all view controllers below it.

    0 讨论(0)
提交回复
热议问题