I use the method hidesBottomBarWhenPushed
when push, and at many places, the UITabBar needs hidden when push and not hidden when pop back, so How can I observe the event ?
There is actually another way to observer if when a UITabBar is hidden or not, it's by using Key-Value Observing (KVO). I had a similar problem and used it to find when the tabBar
got displayed or hidden.
It can look like something like this.
class TabBarController: UITabBarController {
// custom code
var observation: NSKeyValueObservation?
convenience init() {
self.init(nibName: nil, bundle: nil)
observation = observe(
\.tabBar.isHidden,
options: [.old, .new]
) { object, change in
print("TabBar isHidden changed from : \(change.oldValue), updated to: \(change.newValue)")
}
}
deinit {
observation = nil
}
}
If use this in production, make sure you remove the observer and follow best practice for KVO. Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With