【发布时间】: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