【问题标题】:iOS: Can we use different launch screen storyboard for different schema in iOS ApplicationiOS:我们可以为 iOS 应用程序中的不同模式使用不同的启动屏幕故事板吗
【发布时间】:2020-12-03 05:45:52
【问题描述】:

我的应用程序中有 2 个架构:

  1. App_Scheme1
  2. App_Scheme2

enter image description here

我想为他们使用单独的启动屏幕故事板。如果可以,请告诉我吗?

我对此进行了搜索,发现在 URL 方案中是可能的,但在应用程序方案中是不可能的。

我创建了两个不同的启动屏幕故事板。

  1. 启动屏幕
  2. 动态启动屏幕

enter image description here

如何将它们分配给架构?

任何帮助将不胜感激。提前谢谢你。

【问题讨论】:

    标签: ios swift launch-screen


    【解决方案1】:

    嗯,把想要的Launch Screen放在UIWindow的keyWindow上面怎么样?

    UIWindow 是 UIView 的子类,因此很容易在其上放置另一个 UIView。只需在应用完成启动后实施这些即可。

    // AppDelegate callback after app did launch.
    func application(application: UIApplication, 
               didFinishLaunchingWithOptions: launchOptions: [NSObject: AnyObject]?) -> Bool
    

    作为 the found tutorial,iOS 应用程序 100% 以编程方式 swift,它是 UIWindowrootController 全部来自代码。

    【讨论】:

    • 嘿@AechoLiu,感谢您的帮助。这个答案很好,我会试一试,然后会回复。
    【解决方案2】:

    进入 SceneDelegate 文件并在 willConnectTo 函数中手动设置您的入口控制器,如下所示:

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
        // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
        // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
        guard let windowScene = (scene as? UIWindowScene) else { return }
        
        window = UIWindow(windowScene: windowScene)
        window?.backgroundColor = .white
        window?.makeKeyAndVisible()
        let controller = YourPrfereStartController() // set here the name of controller that you want to start
        window?.rootViewController = controller
    }
    

    然后一般删除main,如下图所示

    【讨论】:

    • 感谢您的回复。这是否会在启动时间上产生任何差异或出现任何黑屏?我会试试这个。
    【解决方案3】:

    您可以复制现有的应用程序目标并将其启动屏幕设置为不同的启动屏幕,然后设置您的第二个方案以运行复制的目标。

    启动情节提要在每个目标生成的 Info.plist 文件中定义。如果你想使用默认的方法,那么你必须有不同的目标。如果您想要一个解决方法,例如使用配置的脚本、didFinishLaunchingWithOptions 中或之后的附加 LaunchScreens,那么也许这是可能的,但实现它会更复杂。

    <key>UILaunchStoryboardName</key>
        <string>LaunchScreen</string>
    

    【讨论】:

    • @ Blazej SLEBODA ,是的,这个答案有效。但是如果我们有很多方案,那么就会创建多个重复的目标。这是正确的方法吗。您能否通过使用单个目标和多个模式来帮助我?
    猜你喜欢
    • 2023-03-14
    • 1970-01-01
    • 2016-09-22
    • 1970-01-01
    • 2016-03-07
    • 2017-01-13
    • 2013-11-08
    • 1970-01-01
    • 2017-09-03
    相关资源
    最近更新 更多