I have an application where I have a use case for two UIWindow
instances. 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:
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
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
Edit
Here's the code where I create the UIWindow
:
self.callManagementWindow = ActiveCallManagementWindow(frame: UIScreen.mainScreen().bounds)
self.callManagementWindow.rootViewController = primaryViewController
self.callManagementWindow.hidden = false
self.callManagementWindow.makeKeyAndVisible()
Some time ago I also had issues with two windows and rotation and if I recall right you need to override supportedInterfaceOrientations()
and shouldAutorotate()
in rootViewController
of first UIWindow
as well as second one