[英]Restrict navigation bar from hide on button tap
I wants to hide navigation bar on tap.我想在点击时隐藏导航栏。 So i used this method of navigation bar.所以我使用了这种导航栏的方法。
self.navigationController?.hidesBarsOnTap = true
Have 2 button on screen and when i tap on that button for perform some action it is also hiding navigation bar.屏幕上有 2 个按钮,当我点击该按钮执行某些操作时,它也会隐藏导航栏。 I think button click consider as tap.我认为按钮单击视为点击。
Can you please let me know, is it correct behaviour?你能告诉我,这是正确的行为吗? Also please let me know if there is any way to restrict this.另外请让我知道是否有任何方法可以限制这一点。 I don't want to hide navigation bar on button tap, rest of parts of screen will be fine.我不想在点击按钮时隐藏导航栏,屏幕部分的 rest 就可以了。
You can create your custom button and handle touches on to enable/disable hiding bars eg:您可以创建自定义按钮并处理触摸以启用/禁用隐藏栏,例如:
class BarHideOnTapButton : UIButton {
weak var navigationController: UINavigationController?
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
self.navigationController?.hidesBarsOnTap = false
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
self.navigationController?.hidesBarsOnTap = true
}
}
class ViewController: UIViewController {
@IBOutlet var button: BarHideOnTapButton?
override func viewDidLoad() {
super.viewDidLoad()
self.button?.navigationController = self.navigationController
self.navigationController?.hidesBarsOnTap = true
}
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.