【问题标题】:UIWindow Status Bar RotationUIWindow 状态栏旋转
【发布时间】:2016-09-02 03:22:45
【问题描述】:

我有一个应用程序,其中有两个 UIWindow 实例的用例。第一个实例运行所有正常的应用程序交互,但我需要能够在其他一切之上呈现视图控制器,无论用户在应用程序中做什么,无需用户交互。

我的第二个窗口可以正常工作并且显示正常。在这个视图控制器中,我只支持纵向模式(尽管应用程序的其他部分支持横向)。我尝试在窗口的rootViewController 中使用这些方法阻止旋转:

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
  return [.Portrait]
}

override func shouldAutorotate() -> Bool {
  return false
}

这成功地阻止了设备旋转视图控制器,但它仍然允许状态栏旋转。我也想防止状态栏旋转。我尝试将以下内容添加到我的AppDelegate

func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask {
  if let _ = window as? MyTopWindow {
    return [.Portrait]
  } else {
    return .All
  }
}

但这也没有奏效。状态栏仍在旋转。

我已经看到下面的问题并尝试实施解决方案,但它不适用于我的情况:Status bar rotates separated from UIWindow

编辑

这是我创建 UIWindow 的代码:

self.callManagementWindow = ActiveCallManagementWindow(frame: UIScreen.mainScreen().bounds)
self.callManagementWindow.rootViewController = primaryViewController
self.callManagementWindow.hidden = false
self.callManagementWindow.makeKeyAndVisible()

【问题讨论】:

  • 我应该补充一下 - 如果有人知道我可以使用多个 UIWindow 实例实现此而不的方法,我也准备好了。但是,我不知道有任何其他方法可以确保我始终可以在其他所有内容之上呈现视图控制器。
  • 你能把代码贴在你创建和设置 UIWindows 的地方吗?
  • @kpsharp 添加了代码
  • 试试这个:[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationPortrait;如果没有解决,那么您可以发布剩余 UIWindow 的代码吗?

标签: ios uiviewcontroller uiwindow


【解决方案1】:

前段时间我也遇到了两个窗口和旋转的问题,如果我没记错的话,您需要在第一个 UIWindow 和第二个 rootViewController 中覆盖 supportedInterfaceOrientations()shouldAutorotate()

【讨论】:

  • 我希望不必这样做,但看起来这是必需的。我已经调整了我的代码,所以当主UIWindow 在后台时,那些UIViewControllerssupportedInterfaceOrientationsshouldAutorotate 中返回适合关键窗口的正确值。
【解决方案2】:

你能在primaryViewController的viewDidAppear中试试这个吗:

[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationPortrait;

【讨论】:

    【解决方案3】:

    在我的例子中,我在代码中设置了 UIWindow,同时还指定了 Main storyboard 在Info.plist

    <key>UIMainStoryboardFile</key>
        <string>Main</string>
    

    Main.storyboard 有一个简单的初始 ViewController(这个 ViewController 没有指定任何方向)

    解决方案是删除UIMainStoryboardFile(在Info.plist 或一般 -> 目标 -> 部署信息 -> 主界面)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-14
      相关资源
      最近更新 更多