【问题标题】:Launching into portrait-orientation from an iPhone 6 Plus home screen in landscape orientation results in wrong orientation从 iPhone 6 Plus 主屏幕横向启动到纵向会导致方向错误
【发布时间】:2014-11-18 03:09:06
【问题描述】:

这个问题的实际标题比我想象的要长:

在 iPhone 6 Plus 上启动根视图控制器仅支持纵向但在其他情况下支持横向的应用,而主屏幕处于横向时会导致应用程序窗口处于横向但设备处于纵向。

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

什么时候应该是这样的:

复制步骤:

  1. 运行 iOS 8.0 的 iPhone 6 Plus。

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

  3. 应用的根视图控制器是一个UITabBarController。

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

  5. 从 iOS 主屏幕开始。

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

  7. 冷启动应用程序。

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

我想不出任何其他方式来强制纵向方向除了完全禁用横向,这是我做不到的:我们的网络浏览器模式视图控制器需要横向。

我什至尝试继承 UITabBarController 并覆盖supportedInterfaceOrientations 以返回仅纵向掩码,但这(即使使用上述所有其他步骤)并没有解决问题。


Here's a link to a sample project showing the bug.


【问题讨论】:

  • 您是否向雷达提交了错误?
  • Apple 论坛上的 Justin Miller 建议如下:“您的信息属性列表应指定您愿意允许应用启动的方向(应对应于初始视图控制器支持的方向) )。”
  • 我喜欢你提出问题的方式。我想知道如何表达。谢谢你拯救了我的一天。 !!!

标签: ios iphone ios8 uiinterfaceorientation


【解决方案1】:

在 iPhone 6 Plus 上以横向方式启动我们的应用时,我遇到了同样的问题。

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

并在应用委托中实现 application:supportedInterfaceOrientationsForWindow::

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

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

【讨论】:

  • 这对我有用。该应用程序仅在允许的方向上启动,但随后的 viewControllers 可以旋转到“几乎颠倒”,这取决于您的 VC 指定的内容。谢谢!
  • 哇!太感谢了!!!这对我有帮助: iPhone 6 Plus (device OR simulator) 。我必须支持画廊视图的所有旋转,但只支持主要视图的肖像。如果应用程序启动,然后最小化,然后 iPhone 6 Plus 主屏幕旋转到横向,然后应用程序再次打开 - 一切看起来都是纵向的,但通知中心/底部配置面板可以从侧面向下/向上拉。 (并且 iOS 警报也出现了旋转)...这修复了它!
  • 不错1。谢谢你。我想知道为什么它只是 6+ 的问题?
  • @Helium3 我怀疑这与 6 Plus 支持环境中的 SpringBoard 有关。
  • 这是仪式解决方案
【解决方案2】:

设置UIApplicationstatusBarOrientation 似乎对我有用。我把它放在了应用委托的application:didFinishLaunchingWithOptions: 方法中。

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

    // the rest of the method
}

【讨论】:

  • 这对我有用,虽然我没有使用 UITabBarController 作为根视图控制器,其他答案表明这是原始帖子的主要问题。
  • 将其移至 - (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions 如果您使用状态恢复,效果会更好。
  • 这太棒了。你把我从灾难中救了出来。如果你在旧金山或附近,我会给你买啤酒。
  • statusBarOrientation 是只读属性。苹果Setter for 'statusBarOrientation' was deprecated in iOS 9.0: Explicit setting of the status bar orientation is more limited in iOS 6.0 and later 发出警告。但这是我摆脱错误的唯一方法。
【解决方案3】:

当使用 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];

【讨论】:

  • 很遗憾,这不起作用。真正的解决方法是编辑 Plist 文件,使其与您的应用在启动时的预期行为相匹配。
  • @DJSK 你能提供一个例子吗?我的 UITabBarController 遇到了类似的问题。我想支持所有方向,但应用只能以纵向打开。
【解决方案4】:

我只希望我的应用以横向模式打开(并且不会出现您在 iPhone 6 Plus 上描述的问题),因此我将 Landscape (left home button)Landscape (right home button) 设置为我的应用的 PLIST 文件中允许的唯一方向。这解决了我的应用程序打开时的方向问题。但是,我需要我的应用程序仅支持一个视图的纵向模式,因为我在我的应用程序中显示UIImagePickerController,Apple 要求它在 iPhone 上以纵向模式显示。

通过在AppDelegate 中包含以下代码,我能够仅支持该一个视图的纵向,同时保持我的应用以横向模式打开:

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {

        return UIInterfaceOrientationMaskAllButUpsideDown;

    } else {

        return UIInterfaceOrientationMaskAll;

    }

}

【讨论】:

    【解决方案5】:

    我有一个非常相似的问题。除了播放视频之外,我想在所有地方强制使用纵向模式。

    我所做的是:

    1) 在 AppDelegate 中强制应用方向为纵向:

    -(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
    {
        if ([window.rootViewController.presentedViewController isKindOfClass:[MPMoviePlayerViewController class]])
        {
            return UIInterfaceOrientationMaskAll;
        }
        return UIInterfaceOrientationMaskPortrait;
    }
    

    2) 启动一个空的模式视图控制器解决了我的问题。 我在 NavigationViewController 根目录上的第一个视图控制器的 viewDidLoad 中启动它(应用程序启动后可见的第一个视图控制器):

    - (void)showAndHideNamelessViewControllerToFixOrientation {
        UIViewController* viewController = [[UIViewController alloc] init];
        [self presentViewController:viewController animated:NO completion:nil];
        [viewController dismissViewControllerAnimated:NO completion:nil];
    }
    

    【讨论】:

      【解决方案6】:

      请尝试以下代码。 可能这个问题是由横向启动时的 keywindow 大小引起的。

      // in application:didFinishLaunchingWithOptions: ...
      
      self.window.rootViewController = self.viewController;
      [self.window makeKeyAndVisible];
      [self.window setFrame:[[UIScreen mainScreen] bounds]]; //<- ADD!!
      

      【讨论】:

      • 不。试试文末附上的示例项目看看。
      • 对不起,我错过了示例项目。但是我通过在 makeKeyAndVisible 之后强制窗口框架使项目正常工作。
      • 这对我有用,而且我没有使用 UITabBarController。谢谢!
      【解决方案7】:

      Jared 使用通用容器视图控制器的解决方法对我来说不走运。我已经使用supportedInterfaceOrientations 对标签栏控制器进行了子类化,但也没有运气。无论启动后 6+ 的方向如何,标签栏的窗口都会报告 frame = (0 0; 736 414)

      到目前为止,我发现的唯一解决方法是在 makeKeyAndVisible 之后强制窗口框架

      [self.window makeKeyAndVisible]; self.window.frame = CGRectMake(0, 0, MIN(CGRectGetWidth(self.window.frame), CGRectGetHeight(self.window.frame)), MAX(CGRectGetWidth(self.window.frame), CGRectGetHeight(self.window.frame)));

      【讨论】:

      • 这几乎可以工作。视图的方向以纵向正确显示,但状态栏仍卡在横向。
      【解决方案8】:

      我的应用程序出现了同样的错误,我通过solution 解决了这个问题

      首先它不起作用,但经过一番挖掘后,我必须在启动画面后在初始控制器上进行操作。

      答案是 OjbC 语言,让我将其更新为 Swift

      override var shouldAutorotate: Bool {
          return true
      }
      
      override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
          return .portrait
      }
      

      不要忘记应该在初始视图控制器上。

      【讨论】:

        【解决方案9】:

        就我自己而言,我遇到了与 jaredsinclair 相同的问题,但是使用 supportedInterfaceOrientations 方法子类化 UIViewController 并不能解决问题。相反,我完全按照他在我的AppDelegateappDidFinishLaunching 方法中所做的事情,并将我的UITabBarController 作为一个孩子添加到一个普通的UIViewController 而不是他的子类中,并且它起作用了!

        【讨论】:

          【解决方案10】:

          我处于同样的情况,并且执行 [self.window setFrame:...] 对我不起作用。

          在应用程序末尾添加以下内容:didFinishLaunchingWithOptions 是我发现的唯一可行的方法。它使屏幕闪烁,并不完全干净和高效。

          我在应用程序末尾添加了这个:didFinishLaunchingWithOptions:

          UIViewController *portraitViewController = [[UIViewController alloc] init];
          UINavigationController* nc = [[UINavigationController alloc] initWithRootViewController:portraitViewController];
          [self.navController presentViewController:nc animated:NO completion:nil];
          [self.navController dismissViewControllerAnimated:NO completion:nil];  
          [UIViewController attemptRotationToDeviceOrientation];
          

          【讨论】:

            【解决方案11】:

            我有一个类似的问题是我的应用程序以 UITabBarController 作为根视图控制器以横向和纵向运行。

            每当应用程序在横向模式下启动时,视图都是不正确的。

            我要做的就是: - 删除 XIB 中的 rootview 控制器分配。 - 应用启动后手动添加:


            • (void)applicationDidFinishLaunching:(UIApplication *)application { application.statusBarHidden = YES;

              [self.window setRootViewController:self.tabBarController];


            这解决了问题。

            【讨论】:

              【解决方案12】:

              只需删除 info.plist 中支持的界面方向中的所有项目,除了你想要的(我只需要肖像),它将适用于我

              【讨论】:

                【解决方案13】:

                只要打电话 [应用程序 setStatusBarOrientation:UIInterfaceOrientationPortrait 动画:NO]; 在应用程序委托方法中 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

                其实设备现在是 UIInterfaceOrientationPortrait 后 Launching ,如果你触摸一个 inputField ,键盘是纵向布局

                【讨论】:

                  猜你喜欢
                  • 2014-11-11
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 2014-11-05
                  • 2015-01-27
                  • 2015-12-30
                  • 1970-01-01
                  • 1970-01-01
                  相关资源
                  最近更新 更多