从横向方向从iPhone 6 Plus主屏幕启动纵向导致错误的方向

jar*_*air 59 iphone uiinterfaceorientation ios ios8

这个问题的实际标题比我可能适合的长:

启动一个应用程序,其根视图控制器仅支持纵向,但在主屏幕处于横向方向时支持iPhone 6 Plus上的横向方向会导致应用程序窗口处于横向方向但设备为在纵向方向.

简而言之,它看起来像这样:

当它应该看起来像这样:

重现步骤:

  1. iPhone 6 Plus运行iOS 8.0.

  2. 一个应用程序,其plist支持所有但纵向倒置的方向.

  3. 应用程序的根视图控制器是UITabBarController.

  4. 一切,标签栏控制器及其所有后代子视图控制器都UIInterfaceOrientationMaskPortrait从中返回supportedInterfaceOrientations.

  5. 从iOS主屏幕开始.

  6. 旋转至横向(需要iPhone 6 Plus).

  7. 冷启动应用程序.

  8. 结果:界面方向损坏.

除了完全禁用横向之外,我无法想到强制执行纵向定位的任何其他方式,这是我无法做到的:我们的网络浏览器模态视图控制器需要横向.

我甚至尝试了子类化UITabBarController并重写supportedInterfaceOrientations以返回仅限纵向的掩码,但是这(即使使用上述所有其他步骤)也没有解决问题.


这是一个显示错误的示例项目的链接.


Ste*_*rch 78

在iPhone 6 Plus上以横向方式启动应用程序时遇到了同样的问题.

我们的修复是通过项目设置从plist中删除横向支持的界面方向:

删除了横向方向

并实现应用程序:supportedInterfaceOrientationsForWindow:在app delegate中:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    return UIInterfaceOrientationMaskAllButUpsideDown;
}
Run Code Online (Sandbox Code Playgroud)

显然,plist中的信息是指定允许您的应用启动的方向.


小智 38

设置statusBarOrientationUIApplication,似乎为我工作.我将它放在application:didFinishLaunchingWithOptions:app delegate 中的方法中.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    application.statusBarOrientation = UIInterfaceOrientationPortrait;

    // the rest of the method
}
Run Code Online (Sandbox Code Playgroud)


jar*_*air 6

当使用UITabBarController作为根视图控制器时,这似乎是iOS 8中的一个错误.解决方法是使用大多数香草UIViewController作为根视图控制器.此vanilla视图控制器将用作选项卡栏控制器的父视图控制器:

///------------------------
/// 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];
Run Code Online (Sandbox Code Playgroud)