開發(fā)過程中,會遇到導航欄透明問題。如下圖的需求:


要實現(xiàn)這個效果要注意到的點:
1、系統(tǒng)有提供隱藏導航欄的方法
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
if navigationController?.navigationBarHidden ==? false {
navigationController?.setNavigationBarHidden(true, animated: true)
}
}
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
if navigationController?.navigationBarHidden == true {
navigationController?.setNavigationBarHidden(false, animated: true)
}
}
2、隱藏導航欄后要自己加一個視圖,擁有返回按鈕,按鈕要足夠寬,保證點擊范圍,同時返回箭頭要靠左

3、導航欄隱藏之后,返回手勢會失效
這里我們需要創(chuàng)建一個navigationcontroller 類增加如下代碼:
override func viewDidLoad() {
super.viewDidLoad()
if respondsToSelector(Selector("interactivePopGestureRecognizer")) {
interactivePopGestureRecognizer?.delegate = self
delegate = self
}
// Do any additional setup after loading the view.
}
注意要加上UINavigationControllerDelegate,UIGestureRecognizerDelegate
然后在storyboard 中設置navigationvc 的類為這個類
代碼戳這 ——> TranslucentNavigationController?