【问题标题】:UIButton above navigation bar. Touch up event doesn't work导航栏上方的 UIButton。修饰事件不起作用
【发布时间】:2020-08-07 21:51:29
【问题描述】:

我有一个带有“关闭”按钮的视图控制器,它位于导航栏的位置。 看起来是这样的:

我隐藏导航栏的代码:

    self.navigationController!.navigationBar.setBackgroundImage(UIImage(), for: .default)
    self.navigationController!.navigationBar.shadowImage = UIImage()
    self.navigationController!.navigationBar.isTranslucent = true
    navItem.setHidesBackButton(true, animated: true)

按钮可见,但修饰事件不起作用。如果我将按钮移动到导航栏区域下方,一切正常。

我试过了:

    self.navigationController!.navigationBar.isUserInteractionEnabled = true
    self.navigationController!.navigationBar.isExclusiveTouch = false

不幸的是,它没有帮助。我该如何解决这个问题?

【问题讨论】:

  • 您的代码应该可以工作,但如果您遇到按钮调用问题,那么肯定是其他地方存在问题,您能否在这里分享您的代码 zip,以便我可以帮助您
  • 嗨,它是这样工作还是完全不工作? stackoverflow.com/questions/61278358/…
  • 您是否有理由不隐藏导航栏? self.navigationController?.setNavigationBarHidden(true, animated: false)

标签: ios swift uibutton autolayout uinavigationbar


【解决方案1】:

关闭按钮不是导航栏按钮吗?

navigationItem.rightBarButtonItem?.isEnabled = true

navigationItem.rightBarButtonItem = UIBarButtonItem(title: "CLOSE", style: .done, target: self, action: #selector(handleRightBarButton))

@objc handleRightBarButton()
{
    //Hide function here? 
}

【讨论】:

    猜你喜欢
    • 2016-05-31
    • 2020-08-07
    • 2014-08-21
    • 1970-01-01
    • 2019-01-15
    • 2023-01-14
    • 2014-10-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多