我正在使用Tab Bar Controller
,它运行正常,但是当我的应用程序首次启动我的入门屏幕以便用户接受条款和条件时,标签栏会消失。
我不太清楚在这做什么。这是我的代码:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
//tnc screen ----------------------------------------------
let launchedBefore = UserDefaults.standard.bool(forKey: "hasLaunched")
self.window = UIWindow(frame: UIScreen.main.bounds)
let launchStoryboard = UIStoryboard(name: "Onboarding", bundle: nil)
let mainStoryboard = UIStoryboard (name: "Main", bundle: nil)
var vc: UIViewController
if launchedBefore {
vc = mainStoryboard.instantiateInitialViewController()!
} else {
vc = launchStoryboard.instantiateViewController(withIdentifier: "FirstLaunch")
}
UserDefaults.standard.set(true, forKey: "hasLaunched")
self.window?.rootViewController = vc
self.window?.makeKeyAndVisible()
//end tnc screen ---------------------------------------------
我该怎么解决这个问题?
这是因为你用T&C故事板模糊了你的UITabBarController
故事板。
我倾向于完全抛弃故事板,有一个根UITabBarController
,并且在UIViewControllers
管理的TabBarController
之一,添加了T&C接受的子视图。
开沟故事板看起来像这样:
UIWindow
--UITabBarController (the windows root view controller)
----UIViewController for tab 1
------UIView to show T&C
----UIViewController for tab 2
----UIViewController for tab n
我设法通过将此添加到我的同意按钮(使用我的tncs在故事板上)来修复它:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
self.present(homeVC, animated: true, completion: nil)*/
let controller = storyboard.instantiateViewController(withIdentifier: "TabBarController"); addChild(controller)
view.addSubview(controller.view)
controller.didMove(toParent: self)
非常感谢@Woodstock和@Teetz帮助我理解它背后的逻辑! :)