2017-04-15 55 views
0

視圖控制器被推動和底部標籤欄被隱藏,像這樣:爲什麼hidesBottomBarWhenPed不工作時沒有根視圖控制器?

let myViewController = self.storyboard?.instantiateViewController(withIdentifier: MyViewController) as! MyViewController 
myViewController.hidesBottomBarWhenPushed = true 
navigationController?.pushViewController(myViewController, animated: true) 

即正常工作。

但是,當我更改根視圖控制器之前推底部欄不隱藏。

// Change the root view controller 
let firstRootViewController = UIApplication.shared.keyWindow!.rootViewController 
UIApplication.shared.keyWindow!.rootViewController = secondRootViewController 

// Push view on stack of navigation controller which is a child of firstRootViewController 
let myViewController = self.storyboard?.instantiateViewController(withIdentifier: MyViewController) as! MyViewController 
myViewController.hidesBottomBarWhenPushed = true 
navigationController?.pushViewController(myViewController, animated: true) 

// Some more things happen... 

// Switch back to previous root view controller 
UIApplication.shared.keyWindow!.rootViewController = firstRootViewController 

其結果是,導航控制器正確地推myViewController但底部欄可見,彷彿參數hidesBottomBarWhenPushed被忽略。

這裏有什麼問題?

回答

1

的解決方案是不改變根視圖控制器,但僅將視圖添加到keyWindow:

// Add another view on top of all views 
UIApplication.shared.keyWindow?.addSubView(self.view) 

// Push view on stack of navigation controller which is a child of firstRootViewController 
let myViewController = self.storyboard?.instantiateViewController(withIdentifier: MyViewController) as! MyViewController 
myViewController.hidesBottomBarWhenPushed = true 
navigationController?.pushViewController(myViewController, animated: true) 

// Some more things happen... 

// Remove topmost view 
self.view.removeFromSuperview() 
相關問題