ios – Swift, UISceneDelegate UIScene overlay keyboard



I’m porting my app from non-SceneDelegate to become an app that supports SceneDelegate…

I’ve run into a problem where my custom “AlertView”, which used to overlay the keyboard, no longer appears to overlay the keyboard, and instead appears “behind” the keyboard. Even with windowLevel set properly

I’m using the code block to present my custom “scene”, which is effectively a blank UIWindow where I embed a customized “AlertView”

let sceneDelegate = UIApplication.shared.connectedScenes.first?.delegate as? SceneDelegate

let controller = AlertViewController()
controller.alertView = alertView
// create the uiwindow
sceneDelegate?.alertWindow = UIWindow(frame: (view.window?.frame)!)
sceneDelegate?.alertWindow?.windowScene = self.view.window?.windowScene
sceneDelegate?.alertWindow?.windowLevel = UIWindow.Level.alert + 1
sceneDelegate?.alertWindow?.backgroundColor = .red.withAlphaComponent(0.5)
sceneDelegate?.alertWindow?.rootViewController = controller
sceneDelegate?.alertWindow?.isHidden = false

It appears that calling


Dismisses the keyboard (and the newly created UIWindow sits behind the keyboard), whereas calling

sceneDelegate?.alertWindow?.isHidden = false

Still presents the UIWindow but does not dismiss the keyboard.

Am I missing something here in my setup to make my UIWindow appear “above” the keyboard, without dismissing the keyboard?

Does Apple allow us to overlay on top of the keyboard anymore? Or was that only available with UIWindow?

Thank you.

As you can see, the “red” background I added for testing should appear above the keyboard as it did when working with UIApplication.shared.window