2017-04-02 35 views
0

移動後退按鈕來customNavigationbar在viewWillAppear我隱藏我的navigationControllernavigationBar這樣的:從默認UINavigationBar的在迅速

override func viewWillAppear(_ animated: Bool) { 
     super.viewWillAppear(animated) 
     self.navigationController?.setNavigationBarHidden(true, animated: true) 
     self.navigationController?.interactivePopGestureRecognizer?.delegate = nil 
} 

然後我在Storyboard增加了navigationBar,在我UIViewController它連接到一個IBOutlet進行定製來自IB。

一切工作正常,但我不能將默認backButton從原始隱藏navigatioBar移動到我的新自定義navigationBar

問:

有從默認navigationBar移動backButton這一新的自定義navigationBar **

注道:?我不想添加自定義後退按鈕。

+0

爲什麼你添加一個自定義導航欄,當你已經有一個你正在隱藏的導航條? – 2017-04-02 23:41:27

+0

@Sneak,因爲我的第一個viewcontroller得到非半透明的導航欄,而我的第二個viewcontroller需要一個半透明的導航欄。當你在第二個視圖控制器上更改isTranslucent時,會從推送到第二個視圖控制器中得到一個奇怪的動畫。所以我需要一個定製的導航欄,以解決這個問題 – Mohammadalijf

+0

我明白了,你試圖改變isTranslucent在viewDidAppear/viewWillAppear中沒有成功? – 2017-04-02 23:48:19

回答

1

你不能。你需要創建你自己的UIBarButtonItem

let backItem = UIBarButtonItem(title: "Back", style: .plain, target: self, action: #selector(yourSelector)) 
self.navigationItem.leftBarButtonItem = backItem 
+0

看起來像我應該在我所有的viewcontrollers中使用customnavigaitonbar,併爲導航條使用自定義的後退按鈕。謝謝 – Mohammadalijf