繁体   English   中英

如何仅在导航栏的栏按钮项中启用用户交互?

[英]How to enable the userinteraction only in the barbutton item of the navigation bar?

我有一个应用程序,它具有像 UI 一样的新 Facebook 应用程序。 在那里,有一个侧面菜单控制器。 它在导航栏上有一个按钮,点击它会给你菜单。 但我的问题是在我使用的示例中,导航栏也可以移动,我通过在导航栏中设置 userinteractionenabled=no 来解决这个问题。 但我只需要在导航栏中的按钮中启用用户交互。 如果我喜欢我所做的整个导航栏变得不可点击。 有人可以帮助我实现这一目标吗?

如果您有自定义按钮,请使用此按钮

UIBarButtonItem *button = self.navigationItem.rightBarButtonItem;
button.enabled = NO;

这是我使用的代码。 它并不能完全启用用户交互,但我想出了如何将标题设置为白色,然后在单击时更改颜色。 (看 setTitleColor 行覆盖 func viewDidLoad() { super.viewDidLoad()

let handleButton = UIButton.init(type: .custom)
    button.setTitle("Register", for: .normal)
    button.layer.backgroundColor = CGColor.init(gray: 0.0, alpha: 0.0)
    button.setTitleColor(.white, for: .normal)
    button.setTitleColor(.red, for: .highlighted)
       button.layer.borderWidth = 1
       button.layer.cornerRadius = 5
       button.layer.borderColor = UIColor.white.cgColor
    self.navigationItem.rightBarButtonItem = UIBarButtonItem(customView: button)

    button.addTarget(self, action: #selector(didTapRegister), for: .touchUpInside)
    
    if let button = self.navigationItem.rightBarButtonItem?.customView {
        button.frame = CGRect(x:0, y:0, width:80, height:34)
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM