在swift 5中隐藏启动屏幕中的选项卡栏



我已经在iOS应用程序中实现了启动屏幕。它有2-3秒的持续时间,但我主屏幕上的tabarcontroller显示在启动屏幕中。在此处输入图像描述

一种方法是在AppDelegate中为启动屏幕添加一个单独的窗口。这使得您可以将选项卡栏控制器保留为根视图控制器。

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
let launchView = UIStoryboard(name: "LaunchScreen", bundle: nil).instantiateInitialViewController()?.view ?? UIView()
func application(_ application: UIApplication, didFinishLaunchingWithOptions 
launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
launchView.frame = window?.frame ?? .zero
window?.addSubview(launchView)
DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
// splash screen shows for 5 seconds
launchView.removeFromSuperview()
}
return true
}
}

最新更新