2017-10-13 61 views
2

我編程方式創建UINavigationController編程方式創建的UINavigationController與在UIStatusBar大標題瀑布

navigationController = UINavigationController(rootViewController: modeSelectVC!) 
navigationController?.delegate = self 

window.rootViewController = navigationController 
window.makeKeyAndVisible() 

然後定製我UINavigationBar外觀像這樣:

navigationBarAppereance.barTintColor = UIColor.ColorPalette.bostonUniversityRed 
navigationBarAppereance.tintColor = UIColor.ColorPalette.eerieBlack 
navigationBarAppereance.barStyle = .black 
navigationBarAppereance.isTranslucent = true 
navigationBarAppereance.prefersLargeTitles = true 
navigationBarAppereance.largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.ColorPalette.babyPowder] 

配置的UINavigationBar隱藏在rootViewController與狀態欄一起提供,但當rootViewController推動另一個視圖控制器時,狀態欄和導航欄變得可見,如s ○:

UINavigationController with problematic <code>Back</code> button placement

結果是我編程它是但您還可以在上面看到,該back按鈕錯位。如果我放棄喜歡的大標題,那麼後退按鈕就像往常一樣正確對齊,但爲什麼在使用大標題時會出現錯位。

回答

2

我有種解決了這個問題。一旦我在初始視圖控制器上啓用狀態欄,之後,無論呈現什麼狀態,都會正確顯示導航欄和狀態欄。

我仍然不知道是什麼導致了這個問題(如果它是我的或糟糕的文檔的實現錯誤),但處理UINavigationBar可能會很棘手!

2

有這個here一個很好的答案:

You should pin the top of the navigation bar to the bottom of the status bar and use the UIBarPositioningDelegate mechanism to set its position to .topAttached, which will cause it to stretch under the status bar correctly.

+0

我添加了這個:'func position(for bar:UIBarPositioning) - > UIBarPosition {return .topAttached}'但是很遺憾,問題仍然存在。 –

+0

@CanSürmeli可能試試'navigationController.navigationBar.clipsToBounds = false'? –

+0

不幸的是,再沒有。 –