[英]How to enable the userinteraction only in the barbutton item of the navigation bar?
I have an application which is having the new Facebook App like UI.我有一个应用程序,它具有像 UI 一样的新 Facebook 应用程序。 In that, a side menu controller is there.
在那里,有一个侧面菜单控制器。 It has a button on the navigation bar while clicking on to it will give u the menu.
它在导航栏上有一个按钮,点击它会给你菜单。 But my problem is in the sample I am using the navigation bar is also can be movable, I fix this by setting userinteractionenabled=no in the navigation bar.
但我的问题是在我使用的示例中,导航栏也可以移动,我通过在导航栏中设置 userinteractionenabled=no 来解决这个问题。 But I need to enable the userinteraction only in the buttons in the navigation bar.
但我只需要在导航栏中的按钮中启用用户交互。 If I do like what I did the whole navigation bar is became not clickable.
如果我喜欢我所做的整个导航栏变得不可点击。 Can anybody help me in achieving this?
有人可以帮助我实现这一目标吗?
If you have custom button then use this 如果您有自定义按钮,请使用此按钮
UIBarButtonItem *button = self.navigationItem.rightBarButtonItem;
button.enabled = NO;
This is the code I use.这是我使用的代码。 It doesn't quite enable user interaction, but I figured out how to set the title white then when clicked change colors.
它并不能完全启用用户交互,但我想出了如何将标题设置为白色,然后在单击时更改颜色。 (look at setTitleColor lines override func viewDidLoad() { super.viewDidLoad()
(看 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.