[英]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. 我通过storyboard
UINaviationController
添加了一个UINaviationController
并带有选定的选项,如“ On Tap
Hide Bars
On Tap
等。我想知道什么是对NavigationBar和工具栏显示/隐藏做出反应的最佳解决方案。 I tried overriding UINavigationController
and methods like setNavigationBarHidden(_ hidden: Bool, animated: Bool)
, but this doesn't get called when you tap to hide. 我尝试覆盖UINavigationController
和诸如setNavigationBarHidden(_ hidden: Bool, animated: Bool)
,但是在您单击以隐藏时不会调用此方法。 I think it's probably possible to observe some variable, but I'm not sure which one and if it will work. 我认为可能有可能观察到一些变量,但是我不确定哪个变量是否有效。
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")
})
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.