The ReplayKit recording will only capture the main window of your application. When designing for screen recording, you can place any UI elements in a separate UIWindow object. Although applications typically only have one UIWindow, iOS allows many windows. A UIWindow requires a .rootViewController to provide content.
How do I create another UIWindow in SwiftUI?
According to this article it is possible to implement it on UIKit.
main view controls UIWindow and player UIWindow
I tried adding a new UIWindow like this and it didn't work.
extension UIApplication {
var windowScene: UIWindowScene? {
// Get connected scenes
return UIApplication.shared.connectedScenes
// Keep only active scenes, onscreen and visible to the user
.filter { $0.activationState == .foregroundActive }
// Keep only the first `UIWindowScene`
.first(where: { $0 is UIWindowScene })
// Get its associated windows
.flatMap({ $0 as? UIWindowScene })
}
}
struct ContentView: View {
var body: some View {
VStack {
Button("Open New Window") {
if let windowScene = UIApplication.shared.windowScene {
let newWindow = UIWindow(frame: UIScreen.main.bounds)
newWindow.windowScene = windowScene
newWindow.rootViewController = UIHostingController(rootView: Text("This is another view!"))
newWindow.makeKeyAndVisible()
}
}
}
}
}
In SwiftUI, the recommended approach for managing multiple windows is by using the @State property wrapper and WindowGroup structure provided by the SwiftUI framework. Here's an example of how you can create and manage multiple windows in SwiftUI: