UIWindow 状态栏旋转

UIWindow Status Bar Rotation

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

我有第二个 window 工作和呈现良好。在这个视图控制器中,我只支持纵向模式(虽然应用程序的其他部分支持横向)。我试图在 window:

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()

你能在 primaryViewController 的 viewDidAppear 中尝试一下吗:

[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationPortrait;

前段时间我也遇到了两个 windows 和旋转的问题,如果我没记错的话,你需要覆盖第一个 rootViewController 中的 supportedInterfaceOrientations()shouldAutorotate() =13=] 以及第二个

就我而言,我在代码中设置了 UIWindow,同时还指定了主故事板 在 Info.plist

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

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

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