gpt4 book ai didi

ios - 在 SwiftUI 中创建项目后,我们可以将 Root View Controller 更改为 Storybord 吗?

转载 作者:行者123 更新时间:2023-11-28 23:30:12 26 4
gpt4 key购买 nike

我曾尝试遵循

  1. 替换SceneDelegate中的以下代码

    let window = UIWindow(frame: UIScreen.main.bounds)
    window.rootViewController = UIHostingController(rootView: ContentView())
    self.window = window
    window.makeKeyAndVisible()

相反

guard let _ = (scene as? UIWindowScene) else { return }

还将主界面设置为 Storyboard和入口点。

Issue : Getting black screen after launch Launching screen

最佳答案

使用 Xcode 11 beta 3,我可以通过以下步骤可靠地将 Storyboard用作新 SwiftUI 项目中的 Root View Controller :

  1. 注释掉 SceneDelegate 的 scene(willConnectTo:) 函数中的代码。

  2. 创建一个新的 Main.storyboard,添加一个 View Controller ,并在其上设置“Is Initial View Controller”。

  3. 选择 iOS 目标的 Info.plist,右键单击“打开为”->“源代码”。

  4. 添加 UISceneStoryboardFileUIMainStoryboardFile 键,如下所示:

Info.plist snippet

在目标的部署信息部分中设置主界面仅设置 UIMainStoryboardFile 键,但我必须同时设置这两个键才能使其正常工作。

这是 Info.plist 的完整代码:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<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>
<key>UISceneStoryboardFile</key>
<string>Main</string>
</dict>
</array>
</dict>
</dict>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>

关于ios - 在 SwiftUI 中创建项目后,我们可以将 Root View Controller 更改为 Storybord 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56863768/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com