Launching into portrait-orientation from an iPhone 6 Plus home screen in landscape orientation results in wrong orientation

前端 未结 13 1547
南方客
南方客 2020-12-22 23:21

The actual title for this question is longer than I can possibly fit:

Launching an app whose root view controller only supports portrait-orientation but which otherw

相关标签:
13条回答
  • 2020-12-22 23:50

    This appears to be a bug in iOS 8 when using a UITabBarController as a root view controller. A workaround is to use a mostly vanilla UIViewController as the root view controller. This vanilla view controller will serve as the parent view controller of your tab bar controller:

    ///------------------------
    /// Portrait-Only Container
    ///------------------------
    
    @interface PortraitOnlyContainerViewController : UIViewController
    
    @end
    
    @implementation PortraitOnlyContainerViewController
    
    - (NSUInteger)supportedInterfaceOrientations {
        return UIInterfaceOrientationMaskPortrait;
    }
    
    @end
    
    // Elsewhere, in app did finish launching ...
    
    PortraitOnlyContainerViewController *container = nil;
    
    container = [[PortraitOnlyContainerViewController alloc] 
                  initWithNibName:nil 
                  bundle:nil];
    
    [container addChildViewController:self.tabBarController];
    self.tabBarController.view.frame = container.view.bounds;
    [container.view addSubview:self.tabBarController.view];
    [self.tabBarController didMoveToParentViewController:container];
    
    [self.window setRootViewController:container];
    
    0 讨论(0)
提交回复
热议问题