【问题标题】:Force launch orientation for an app supporting all orientations支持所有方向的应用程序的强制启动方向
【发布时间】:2019-04-30 05:16:53
【问题描述】:

我有一个 iOS8 应用程序,我需要在玩游戏时支持所有方向,但在菜单中时,它只是纵向的。我希望应用程序仅使用纵向图像启动,因此它与纵向菜单相匹配。我遇到的问题是我必须在 Info.pList 文件中设置“UISupportedInterfaceOrientations”以支持所有方向,因为我需要它们全部用于主游戏。如果设备是横向的,这显然会导致我的应用程序以横向模式启动,这是我不想要的。我尝试将 info.pList 文件中的值设置为仅纵向,但这会导致横向模式完全停止工作。

有没有办法允许 info.pList 文件中的所有方向,但强制启动图像仅为纵向?或者在我的代码中允许所有方向,但在 info.pList 文件中只指定纵向值?

【问题讨论】:

标签: ios ios8


【解决方案1】:

您应该为 iOS 8 使用“启动屏幕文件”(在 xCode 6+ 中可用)。然后根据需要对启动文件应用约束(您可以根据需要在故事构建器中允许启动 xib 的方向)。即使您希望它用于以前的版本,也可以创建一个单独的初始屏幕并在故事构建器中设置其方向属性。

【讨论】:

    【解决方案2】:

    我也遇到了这个问题,从苹果自己那里找到了很好的解决方案:

    https://developer.apple.com/library/ios/technotes/tn2244/_index.html#//apple_ref/doc/uid/DTS40009012-CH1-ALLOWING_YOUR_APP_TO_ROTATE_INTO_PORTRAIT_ORIENTATION_AFTER_LAUNCH

    它说在 info.plist 中检查所需的启动方向,然后在 appdelegate 中实现此委托方法以在启动后覆盖支持的方向:

    func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask {
        return .AllButUpsideDown
    }
    

    【讨论】:

      【解决方案3】:

      你可以定义一个父视图控制器:

      - (BOOL)shouldAutorotate {
          return YES;
      }
      
      - (NSUInteger)supportedInterfaceOrientations{
          return UIInterfaceOrientationMaskPortrait;
      }
      

      还有你的旋转视图控制器:

      - (BOOL)shouldAutorotate {
          return YES;
      }
      
      
      - (NSUInteger)supportedInterfaceOrientations{
          return UIInterfaceOrientationMaskAll;
      }
      

      【讨论】:

        【解决方案4】:

        为此,您必须遵循两个步骤:

        1- 您只需在Info.plist 文件中选择一个所需的方向。此选择将应用于您的启动屏幕。对于您的示例情况,这应该是UIInterfaceOrientationPortrait

        2- 你必须在你的AppDelegate 中实现func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask。对于您的示例案例实现应该是

        func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
            return .all    
         }

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-02-09
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多