簡體   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