2
votes

When you drag a UINavigationController into a storyboard, you can enable the Hide Bars On Tap option which will hide/show the navigation bar and toolbar upon tapping anywhere in the UIView. This works well except in the case where you don't have a navigation bar and you only have a toolbar. (You checked Shows Toolbar but not Shows Navigation Bar.) When you launch the app there is no visible navigation bar but when you tap a navigation bar slides down from the top, then if you tap again both bars slide away.

How can you use Hide Bars On Tap with only a toolbar and prevent a navigation bar from appearing?

1

1 Answers

0
votes

You can get hold of the gesture recognizer via the barHideOnTapGestureRecognizer property.Then you add actions to this gestureRecognizer to do whatever you want.
In your case ,this snippet will work:`

override func viewDidLoad() {
   super.viewDidLoad()
   navigationController?.hidesBarsOnTap = true

   navigationController?.barHideOnTapGestureRecognizer.addTarget(self, action: "tap:")}


func tap(gest: UIGestureRecognizer){
    navigationController?.navigationBar.hidden = true
}