Damian Dudycz
Damian Dudycz

Reputation: 2810

Observe UINavigationController navigationBar show/hide

I have a UINaviationController added through storyboard with selected options like Hide Bars On Tap etc. I was wondering what is the best solution to react to navigationBar and toolbar shows/hides. I tried overriding UINavigationController and methods like setNavigationBarHidden(_ hidden: Bool, animated: Bool), but this doesn't get called when you tap to hide. I think it's probably possible to observe some variable, but I'm not sure which one and if it will work.

Upvotes: 1

Views: 416

Answers (1)

Shehata Gamal
Shehata Gamal

Reputation: 100543

You can try

var ob:NSKeyValueObservation?

override func viewDidLoad() {
    super.viewDidLoad()

    ob = self.navigationController?.observe(\.navigationBar.isHidden, options: [.new], changeHandler: { (nav, ob) in
        print("ok")
    })
}

Upvotes: 3

Related Questions