Ios 在单独的窗口中锁定状态栏方向

Ios 在单独的窗口中锁定状态栏方向,ios,uiwindow,Ios,Uiwindow,我需要在应用程序中创建一个新的UIWindow。我还希望新窗口以纵向方向锁定,但我的应用程序的原始窗口应以纵向方向锁定 我正在设置我的新窗口,如下所示: newWindow = UIWindow(frame: CGRect(x: 0, y: 0, width: view.bounds.width, height: view.bounds.height)) newWindow?.rootViewController = ViewController2() newWindow?.makeKeyAnd

我需要在应用程序中创建一个新的
UIWindow
。我还希望新窗口以纵向方向锁定,但我的应用程序的原始窗口应以纵向方向锁定

我正在设置我的新窗口,如下所示:

newWindow = UIWindow(frame: CGRect(x: 0, y: 0, width: view.bounds.width, height: view.bounds.height))
newWindow?.rootViewController = ViewController2()
newWindow?.makeKeyAndVisible()
ViewController2
通过以下方式锁定方向:

override var shouldAutorotate: Bool {
    return false
}
问题是,当显示新窗口时,用户旋转设备,应用程序本身将锁定为纵向,但状态栏将旋转为横向模式:

如何确保状态栏也锁定在新窗口内的纵向?


如果有人想在一个简单的项目中看到这一点:

使用此文档解决您的问题

或 解决方案在应用程序代理中。您可以分别处理每个窗口的支持方向,如下所示:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
   // check, which window is asking and return the mask
   return UIInterfaceOrientationMaskAllButUpsideDown;
}

我最终使用了这个委托方法,但是检查传递给该方法的窗口不起作用。我必须检查UIApplication的keyWindow并返回相应的掩码。@AdamJohns您还做了什么才能让它工作?我尝试了这个,但状态栏仍然为我旋转。