ios - 限制导航栏在按钮点击时隐藏
问题描述
我想在点击时隐藏导航栏。所以我使用了这种导航栏的方法。
self.navigationController?.hidesBarsOnTap = true
屏幕上有 2 个按钮,当我点击该按钮执行某些操作时,它也会隐藏导航栏。我认为按钮单击视为点击。
你能告诉我,这是正确的行为吗?另外请让我知道是否有任何方法可以限制这一点。我不想在点击按钮时隐藏导航栏,屏幕的其余部分会很好。
解决方案
您可以创建自定义按钮并处理触摸以启用/禁用隐藏栏,例如:
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
}
...
}
推荐阅读
- php - php访问变量
- javascript - 将元素添加到数组的末尾
- javascript - ReactJS:尝试打印我的数组对象的索引 - 如果我删除元素,它应该动态变化
- c++ - 无法让 `std::enable_if` 为无作用域枚举工作
- python-2.7 - 解码其他语言
- php - tm 额外产品选项选择更改 woocommerce 数量
- c++ - 如何将事件循环中的事件分派给订阅者?
- javascript - 将加载的 3D 对象分配给变量 - 返回未定义
- spring-data-mongodb - Spring data - MongoDB:聚合管道更新不起作用
- python - Python索引值作为元素值