3

I have developed an app that makes use of the iOS8 feature to show or hide the navigation bar on a tap of the view.

However, the main view contains a UIButton which also act upon taps. The problem is that both 'objects' are receiving the tap and if I tap the button, the navigation bar toggles its visibility.

I can get to the barHideOnTapGestureRecognizer via the navigation controller but not really sure what can be done with it to stop it responding if a button is tapped.

Is there a way (apart from switching off or changing to 'Swipe to Hide') to subdue the navigation bar's appearance/disappearance when a button is pressed?

Fittoburst
  • 2,215
  • 2
  • 21
  • 33
  • Did you try to solve with [self.navigationController setNavigationBarHidden:YES]; ? – miletliyusuf Mar 19 '15 at 17:54
  • Well...thanks...that does actually help. It's just a bit tedious that I have to add it to every action handler in my view. I wonder if there's a 'global' way to tell it to not react to button taps. – Fittoburst Mar 19 '15 at 18:10
  • Unfortunetelly there is not which i know. I always type that when i need but i will think about that if i figure it out i will write here. btw i added my answer :) – miletliyusuf Mar 19 '15 at 18:17

2 Answers2

2

Don't use the standard barHideOnTapGestureRecognizer. Fortunately, it's not hard to roll your own:

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
    let gestureRecognizer = UITapGestureRecognizer(target: self, action: "toggleBarsOnTap:")
    self.view.addGestureRecognizer(gestureRecognizer)
}

func toggleBarsOnTap(sender: AnyObject?) {
    let hidden = !self.navigationBarHidden
    self.setNavigationBarHidden(hidden, animated: true)
    self.setToolbarHidden(hidden, animated: true)
}

Taps on the view will show/hide the bars, and taps on controls (subviews of the view) will not.

jrc
  • 20,354
  • 10
  • 69
  • 64
1
[self.navigationController setNavigationBarHidden:YES];
miletliyusuf
  • 982
  • 1
  • 10
  • 12