0

I have a UINavigationController that has a bottom toolbar which I set it's height programatically like so:

navigationController?.toolbar.frame.size.height += 43.0
navigationController?.toolbar.frame.origin.y -= 43.0
navigationController?.hidesBarsOnTap = true

enter image description here

When I tap on my View to hide the bars and tap again to show them, the bottom bar returns to it's default state: enter image description here

How can I preserve the height after the bar shows again?

Thanks a lot! :)

Erez Hod
  • 1,445
  • 1
  • 18
  • 34

1 Answers1

1

There's not a great way to do that, but you can do something like place a tapGestureRecognizer on self.view and count the number of taps.

Something like

    var numTaps = 0
    @IBAction func tapOnView(sender: UITapGestureRecognizer) {
        self.numTaps++
        if numTaps%2==0
        {
            self.navigationController?.toolbar.frame.size.height += 43.0
            self.navigationController?.toolbar.frame.origin.y -= 43.0
        }
    }

    func gestureRecognizer(gestureRecognizer: UIGestureRecognizer,
        shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool{
            return true
    }

It is a little hackish but might work, might try with a slight delay to ensure you set the height after the toolbar's position is set.

Or try one of the answers provided Is there a way to change the height of a UIToolbar? and subclass uitoolbar to override sizeThatFits

Community
  • 1
  • 1
beyowulf
  • 14,133
  • 2
  • 29
  • 36
  • That's actually a good option.. but I'm trying not to do "hacky" tricks too much. Wouldn't it be better if I just created my own toolbar regardless of the one from the UINavigationController and respond to the tapping that hides the Navigationbar? – Erez Hod Nov 03 '15 at 13:06
  • You know your use case better than me. Are you asking what are the conveniences of using UINavigationController's toolbar? Same toolbar across multiple uiviewcontrollers, plays well with auto layout, convenience features like hide on tap, and uniform design/user experience (but you don't seem to like the design, as you want to make it taller). So tradeoffs. – beyowulf Nov 03 '15 at 13:19