SwiftUI iPad 应用在启用多个 window 支持时显示黑屏
SwiftUI iPad app shows black screen on enabling multiple window support
在 macOS Catalina 上使用 SwiftUI,当启用 "Support multiple windows" 时,我的 iPad 应用程序在模拟器中启动时显示黑屏
我正在使用常用的 SwiftUI 项目,唯一的变化是单击 "Support multiple windows" 复选框
这来自我的 SceneDelegate,我认为这是在 SwiftUI
中设置 window 的正确方法
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
let window = UIWindow(frame: UIScreen.main.bounds)
window.rootViewController = UIHostingController(rootView: ContentView())
self.window = window
window.makeKeyAndVisible()
}
在我的 Info.plist 我相信我拥有我需要的一切
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<true/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
</dict>
</array>
</dict>
</dict>
window必须初始化为
let window = UIWindow(windowScene: scene as! UIWindowScene)
在 macOS Catalina 上使用 SwiftUI,当启用 "Support multiple windows" 时,我的 iPad 应用程序在模拟器中启动时显示黑屏
我正在使用常用的 SwiftUI 项目,唯一的变化是单击 "Support multiple windows" 复选框
这来自我的 SceneDelegate,我认为这是在 SwiftUI
中设置 window 的正确方法var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
let window = UIWindow(frame: UIScreen.main.bounds)
window.rootViewController = UIHostingController(rootView: ContentView())
self.window = window
window.makeKeyAndVisible()
}
在我的 Info.plist 我相信我拥有我需要的一切
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<true/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
</dict>
</array>
</dict>
</dict>
window必须初始化为
let window = UIWindow(windowScene: scene as! UIWindowScene)