2017-04-15 19 views
0

뷰 컨트롤러가 밀려와 하단의 탭 표시 줄과 같이 숨겨져 : 잘 작동루트보기 컨트롤러가 아닌데 hidesBottomBarWhenPushed가 작동하지 않는 이유는 무엇입니까?

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()