swift - Swift 3 中的按钮无法单击导航栏后面

标签 swift button swift3 xcode8 navigationbar

我通过代码在导航栏后面的 View 上使用按钮,并取消选择 Storyboard 中的 UnderTopBars 属性,因此我设置了 y 坐标 = -45。当我的导航栏滑到上面时,按钮显示出来,但它没有显示可点击。不触发方法内的修饰

我的代码是

  searchBtn.addTarget(self, action: #selector(ViewController.searchAction(_:)), for: .touchUpInside)

func searchAction(_: UIButton) {

   print("Button Tapped")
}

隐藏导航栏后我的按钮看起来像

enter image description here

最佳答案

enter image description here

您可以使用调试 View 层次结构来判断是否有任何 View 位于按钮顶部???

并确保您的按钮已启用。

关于swift - Swift 3 中的按钮无法单击导航栏后面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46440579/

相关文章:

class - pyqt-如何为 QLabel 类创建点击信号?

ios - 使用 Swift 查找用户是否已显示在 TableView 中

java - Android:点击渐进的可见性变化

arrays - 以编程方式在数组中设置按钮标题

ios - 点击手势出现问题

swift - contains or for-loop,哪个更高效?

Swift 3 转换类型别名闭包转换问题

ios - 突出显示 uitableViewCell

swift 3 : atomic_compare_exchange_strong

ios - 通过应用程序委托(delegate)从 TableView Controller 更改单元格内的值