Junior — Middle
Is it possible to use multiple UIWindow objects in a single application?
sobes.tech AI
Answer from AI
Yes, in an iOS application, it is possible to use multiple UIWindow objects. Usually, the application has one main window (key window), but with the introduction of multiple scenes (UIScene) and external displays, using multiple windows has become common.
Examples of using multiple UIWindow:
- Supporting multiple scenes in iPadOS, where each window corresponds to a separate scene.
- Creating pop-up windows or overlays over the main interface.
- Displaying content on external displays.
It is important to remember that for each UIWindow, you need to properly manage its visibility and hierarchy, as well as assign a rootViewController.
Example of creating an additional window:
let newWindow = UIWindow(frame: UIScreen.main.bounds)
newWindow.rootViewController = UIViewController()
newWindow.windowLevel = .alert + 1 // to make the window appear above the main one
newWindow.makeKeyAndVisible()
Thus, using multiple UIWindow objects is possible and useful in various scenarios.