IOS中LaunchScreen如何设置启动图片与启动页停留时间

软件资讯3个月前更新 admin
153 0

How to set the startup picture and the residence time of the startup page by LaunchScreen in IOS

什么是LaunchScreen

LaunchScreen(启动画面)是iOS应用程序加载过程中展示的一张图片或一个视图,展示给用户一个即将打开应用程序的提示,这意味着Launch Screen是应用程序加载的第一屏幕。

启动图片设置

在启动应用程序之前,iOS需要加载LaunchScreen图片。要设置启动图片,请按照以下步骤操作:

  1. 在Xcode中选中项目,然后选择General类型。
  2. 在DeploymentInfo下找到LaunchScreen选择您的图片或添加新图片
  3. 设置图片的布局和尺寸

启动页面停留时间设置

iOS应用程序默认的启动页停留时间为2秒钟。但是,如果您的应用的启动时间很长,则可以通过设置启动页停留时间来为用户提供更好的体验。

要设置LaunchScreen停留时间,请按照以下步骤操作:

  1. 在info.plist文件中添加一个Key为”UILaunchScreenImage”,类型为String的键值对。
  2. 在这个键值对的value中添加LaunchScreen.storyboard的文件名
  3. 在ViewController中添加延迟时间
class LaunchViewController: UIViewController {
override func viewDidLoad() {
    super.viewDidLoad()
    DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) {
        UIApplication.shared.windows.first?.rootViewController = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController()
    }
}
}
© 版权声明

相关文章

暂无评论

暂无评论...
>