[英]Present ViewController in front of UITabBarController's tabBar and hide this tabBar
[英]Tabbar won't hide when pushed into a ViewController inside a UITabBarController
出於這個問題的目的,我展示了視圖層次結構的精簡版。 我的應用程序包含一個UITabBarController
作為基礎。 每個選項卡的最頂部視圖控制器是導航控制器,並且每個視圖控制器中都嵌入了視圖控制器。
讓我們來第一個選項卡。
UITabBarController-> UINavigationController-> UITableViewController-> UIViewController
假設UITableViewController
實例是某種列表,而UIViewController
是詳細信息視圖。 當用戶點擊列表中的項目時,它將帶您到詳細信息視圖。 當發生這種情況時,我已經將UIViewController
的hidesBottomBarWhenPushed
屬性設置為true
以便當用戶位於詳細視圖中時,底部的選項卡將隱藏。
我的應用程序收到推送通知。 輕觸它們時,它應直接打開到詳細視圖。 我可以將其導航到那里。 但是問題是底部的標簽欄仍然可見!
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
window = UIWindow(frame: UIScreen.main.bounds)
let tabBarController = storyboard.instantiateViewController(withIdentifier: "TabBarController") as! TabBarController
if openingFromPush {
let firstNavigationController = storyboard.instantiateViewController(withIdentifier: "FirstNavigationController") as! UINavigationController
let tableViewController = storyboard.instantiateViewController(withIdentifier: "TableViewController") as! TableViewController
let viewController = storyboard.instantiateViewController(withIdentifier: "ViewController") as! ViewController
viewController.hidesBottomBarWhenPushed = true
firstNavigationController.viewControllers = [tableViewController, viewController]
tabBarController.viewControllers?[0] = firstNavigationController
// tabBarController.tabBar.isHidden = true
window?.rootViewController = tabBarController
} else {
window?.rootViewController = tabBarController
}
window?.makeKeyAndVisible()
return true
}
我在實例化視圖控制器時將相同的hidesBottomBarWhenPushed
屬性設置為true
,但這似乎沒有任何效果。 我什至嘗試直接隱藏像這樣的tabBarController.tabBar.isHidden = true
但這也沒有任何作用。
我不知道如何解決這個問題。 任何幫助,將不勝感激。
如果有幫助,我也會在此處附加示例Xcode項目。
您可以使用以下代碼推送詳細信息視圖控制器:
if openingFromPush {
let viewController = storyboard.instantiateViewController(withIdentifier: "ViewController") as! ViewController
viewController.hidesBottomBarWhenPushed = true
if let nvc = tabBarController.viewControllers?[0] as? UINavigationController {
nvc.pushViewController(viewController, animated: false)
}
window?.rootViewController = tabBarController
}
您無需再次啟動導航視圖控制器和表視圖控制器,因為它已經位於選項卡欄控制器中
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.