Thanks for being a part of WWDC25!

How did we do? We’d love to know your thoughts on this year’s conference. Take the survey here

Avoid rotation in a UIViewController with two UIWindow app

Hi,

I have an iPhone App with an UIWindowScene and two UIWindow's(mainWindow and alertWindow). In the mainWindow I have the whole app and it is allowed to rotate. The alertWindow is a window to show alert's to the user on the top of the screen and I do not want that the content inside rotate.

I thought I may do:

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    return .portrait
}

And

override var shouldAutorotate: Bool {
    return false
}

In the rootviewcontroller of alertWindow but after doing those changes the rootviewcontroller of mainWindow does not rotate until I do any navigation.

I have thought to have two UIWindowScene's (one per UIWindow) but as far I know iPhone app only supports one UIWindowScene.

So, how can I avoid rotation in the viewcontroller of alertWindow without losing the rotation on rootviewcontroller of mainWindow?

My viewcontroller is a UIHostingController, so I tried also to avoid from my SwiftUI view but I did not find any solution neither.

Thank you in advance

I didn't test if that makes a difference, but when overriding supportedInterfaceOrientations, I declare as open var:

override open var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    return .portrait
}

Thanks for reporting if that worked.

Thank you for you answer, but it does not work. The problem is not in the viewcontroller of alertWindow, it is with the below one of mainWindow. This viewcontroller also does not rotate if I set supportedInterfaceOrientations and shouldAutorotate in the viewcontroller of alertWindow.

It is like both viewcontrollers share this properties, but I want that one viewcontroller does not allow rotation but the below one yes.

Thank you

How is the alert presented in the second UIWindow? Is it the root view controller, or is presented on the root view controller?

Not sure if this works but did you try implementing the AppDelegate method:

  • (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window API_AVAILABLE(ios(6.0)) API_UNAVAILABLE(tvos);

I heard UIApplicationDelegate is on the chopping block so even if it does work who knows how long it'll work for (IMO AppDelegate still has useful APIs that scene delegates don't cover and certain things are really quirky to do in a scene delegate) .

I use a separate UIWindow to display some critical alerts too because injecting alerts in the UIViewController hierarchy can lead to some nasty bugs, especially if you run a network operation and get an error, the user might have hit a button and presented or pushed another view controller on screen in the in between but you really want to display that error. Separate UIWindow avoids a lot of potential problems about presenting on detached view controllers, interfering with the state of view controllers the error alert know nothing about, etc. ..But I let my alerts rotate.

Consider whether you really need to do this. Usually you should allow rotation in both windows but if you really can't you can try implementing the method above but note on iPad with resizable windows the concept of orientation doesn't make sense if you're not full screen.

If you're feeling really hacky I guess you could respond to the rotation in the alert window and just move everything where you want it to make it look like it's not rotating but I don't think I'd do that.

Avoid rotation in a UIViewController with two UIWindow app
 
 
Q