简体   繁体   English

iOS:我们可以在 iOS 应用程序中为不同的架构使用不同的启动屏幕 storyboard

[英]iOS: Can we use different launch screen storyboard for different schema in iOS Application

I have 2 schemas in my application:我的应用程序中有 2 个模式:

  1. App_Scheme1 App_Scheme1
  2. App_Scheme2 App_Scheme2

enter image description here在此处输入图像描述

I want to use separate launch screen storyboards for them.我想为他们使用单独的启动屏幕故事板。 Could you please let me know if it is possible?如果可能的话,你能告诉我吗?

I have searched regarding this and I found it is possible in the URL scheme but not in the application scheme.我已经对此进行了搜索,发现在 URL 方案中有可能,但在应用程序方案中没有。

I have created two different launch screen storyboards.我创建了两个不同的启动屏幕故事板。

  1. Launch screen启动画面
  2. Dynamic Launch screen动态启动屏幕

enter image description here在此处输入图像描述

How can I assign them to the schema?如何将它们分配给架构?

Any help will be appreciated.任何帮助将不胜感激。 Thanking you in advance.提前谢谢你。

You can duplicate existing app target and set it's launch screen with different launch screen then set your second scheme to run the duplicated target.您可以复制现有的应用程序目标并将其启动屏幕设置为不同的启动屏幕,然后设置您的第二个方案来运行复制的目标。

The launch storyboard is defined in Info.plist file which is generated per target.启动 storyboard 在每个目标生成的 Info.plist 文件中定义。 If you want to use default way of doing it, then you have to have different targets.如果你想使用默认方式,那么你必须有不同的目标。 If you want a workarounds like scripts which use configs, additional LaunchScreens in or after didFinishLaunchingWithOptions then maybe this will be possible but it will be more complex to achieve it.如果你想要一个解决方法,比如使用配置的脚本,在didFinishLaunchingWithOptions中或之后的额外 LaunchScreens 那么也许这是可能的,但实现它会更复杂。

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

Hmm, how about to put the desired Launch Screen on top of keyWindow of UIWindow?嗯,如何将所需的Launch Screen放在 UIWindow 的keyWindow之上?

UIWindow is a sub-class of UIView, so it's easy to put another UIView on top of it. UIWindow是 UIView 的子类,所以很容易在它上面再放一个 UIView。 Just implement these after app did finish launch.只需在应用程序完成启动后实施这些。

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

As the found tutorial , iOS app 100% programmatically swift, it's UIWindow and rootController all from codes.作为找到的教程,iOS app 100% programmatically swift,它的UIWindowrootController都来自代码。

Go in SceneDelegate file and set your entry controller manually in willConnectTo function like this: SceneDelegate 文件中的 Go 并在 willConnectTo function 中手动设置条目 controller,如下所示:

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
}

After that go in general and delete main like the picture below之后一般为 go 并删除 main 如下图

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM