简体   繁体   English

UIWindow状态栏旋转

[英]UIWindow Status Bar Rotation

I have an application where I have a use case for two UIWindow instances. 我有一个应用程序,我有两个UIWindow实例的用例。 The first instance runs all normal app interactions, but I need to be able to present a view controller above everything else regardless of what the user is doing in the application, without user interaction. 第一个实例运行所有正常的应用程序交互,但我需要能够将视图控制器呈现在其他所有内容之上,而不管用户在应用程序中做了什么,而无需用户交互。

I have the second window working and presenting fine. 我有第二个窗口工作,呈现罚款。 In this view controller, I only support portrait mode (though other parts of the app support landscape). 在这个视图控制器中,我只支持纵向模式(虽然应用程序的其他部分支持横向)。 I've tried to block rotation using these methods in the rootViewController of the window: 我试图在窗口的rootViewController中使用这些方法阻止旋转:

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

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

That successfully prevents the device from rotating the view controller, but it still allows the status bar to rotate. 这成功阻止了设备旋转视图控制器,但它仍然允许状态栏旋转。 I'd like to prevent the status bar from rotating as well. 我想阻止状态栏旋转。 I tried adding the following to my AppDelegate 我尝试将以下内容添加到AppDelegate

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

However that hasn't worked either. 然而,这也没有奏效。 The status bar still rotates. 状态栏仍然旋转。

I've seen the question below and tried to implement the solution but it's not working for my case: Status bar rotates separated from UIWindow 我已经看到了下面的问题,并试图实现解决方案,但它不适用于我的情况: 状态栏旋转分离UIWindow

Edit 编辑

Here's the code where I create the UIWindow : 这是我创建UIWindow的代码:

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

前段时间我也有两个窗口和旋转的问题,如果我rootViewController ,你需要覆盖第一个UIWindow rootViewControllersupportedInterfaceOrientations()rootViewController shouldAutorotate()以及第二个

您可以在primaryViewController的viewDidAppear中尝试这个:

[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationPortrait;

In my case, I setup UIWindow in code, while also specifying Main storyboard in Info.plist 在我的例子中,我在代码中设置UIWindow,同时在Info.plist指定主故事板

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

The Main.storyboard has a simple initial ViewController (this ViewController does not specify any orientations) Main.storyboard有一个简单的初始ViewController (这个ViewController没有指定任何方向)

The solution is removing the UIMainStoryboardFile (in Info.plist or in General -> Targets -> Deployment Info -> Main Interface) 解决方案是删除UIMainStoryboardFile (在Info.plist或在General - > Targets - > Deployment Info - > Main Interface中)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM