ios - 无法按下 NavigationBar 下方的 UIButton?
问题描述
我有一个应用程序,其中有一个可以有导航子的导航控制器。我必须在导航栏通常的位置放置一个 UIButton。
UIButton 连接到目标:
for button in arrayOfButtons {
button.addTarget(self, action: #selector(buttonTouchUpInsideP3), for: [.touchUpInside])
button.addTarget(self, action: #selector(buttonTouchInsideBoundsP3), for: [.touchDown, .touchDragEnter])
button.addTarget(self, action: #selector(buttonDraggedOutOfBoundsP3), for: [.touchDragExit, .touchCancel]) //there is definitly combining that cud be done here...
}
基本上我不能简单地隐藏导航栏,因为我用它来调整大小/自动布局,所以我尝试做的是:(这段代码在子导航控制器的 ViewDidLoad 中)
self.navigationController?.navigationBar.isUserInteractionEnabled = false
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.isTranslucent = true
self.navigationItem.hidesBackButton = true
要删除它的 UI 并让它在那里不可见,这部分可以工作......但是,问题是我仍然无法按下导航栏区域中的任何内容......即使我这样做了isUserInteractionEnabled = false
。
我怎样才能解决这个问题!?这样我就可以点击下方的 UIButton(?)或者更确切地说是导航栏所在的位置?
还没有看到为我解决这个问题的 SO 问题:/
解决方案
好吧,对于任何想知道的人:
@StonedStudio 是对的,我最终只是隐藏了导航栏,而是创建了一个视图,导航栏的边界高度锚定到 view.safeAreaLayoutGuide.topAnchor 的顶部,这样它就形成了导航酒吧同时允许水龙头!:)
推荐阅读
- python - 根据 Maya 时间线移动 PyQt 滑块
- typescript - 如何在 TypeScript 中声明一个全局变量并在 Vue 中使用它
- sql - SQL Pivot 表较大的列值给出了太长的错误
- redis - 带有libev和pthread的异步hiredis,我做错了什么?
- ruby-on-rails - 如何为 Rails 端口配置 ngnix?
- amazon-redshift - 哪个选项最适合选择列压缩编码 [COPY VS ANALYZE COMPRESSION]
- drupal - Drupal 与 xero 的集成
- python-3.x - 预期类型 int 在 Pycharm 中浮动
- java - 从 XPath 查询中获取空值
- leaflet - 使用 font awesome 自定义 react-leaflet 标记图标