UIBarButtonItem不响应点击

时间:2019-01-21 22:32:16

标签: ios swift uinavigationbar wkwebview

我有一个viewController嵌入在navigationController中。从我的viewController中,我以编程方式添加了三个UIBarButtonItem和一个UISearchBar。在导航栏下,我有一个WKWebView,它覆盖了整个屏幕。问题是,UIBarButtonItems在我进行录音或以任何方式与WKWebView交互之前没有响应任何单击。在点击或滚动WKWebView之后,UIBarButtonItems可以正常工作,直到我在UISearchBar中执行搜索为止。 UIBarButtonItems停止再次响应,直到我与WKWebView进行交互。

我曾尝试按照某个论坛帖子中的建议在navigationController?.navigationBar.becomeFirstResponder()DidAppear中添加searchBarTextDidEndEditing。这对问题没有影响。

这是我在DidLoad中启动导航栏的操作:

    self.navigationController?.setNavigationBarHidden(false, animated: true)

    searchBar.delegate = self
    searchBar.sizeToFit()
    searchBar.setImage(UIImage(named: "ssl"), for: .search, state: .normal)
    searchBar.searchBarStyle = .minimal
    searchBar.showsCancelButton = false

    let textField = searchBar.value(forKey: "searchField") as? UITextField
    textField?.textAlignment = .center
    textField?.leftViewMode = UITextField.ViewMode.never
    textField?.clearButtonMode = UITextField.ViewMode.whileEditing
    textField?.keyboardType = .URL
    textField?.autocapitalizationType = .none
    textField?.leftView?.contentMode = .scaleAspectFit

    let back = UIBarButtonItem(image: UIImage(named: "back"), style: .plain, target: self, action: #selector(naviagteBack))
    let forward = UIBarButtonItem(image: UIImage(named: "forward"), style: .plain, target: self, action: #selector(naviagteForward))
    let reload = UIBarButtonItem(image: UIImage(named: "reload"), style: .plain, target: self, action: #selector(navigateReload))

    navigationItem.titleView = searchBar
    reload.tintColor = .black
    navigationItem.rightBarButtonItem = reload

    back.tintColor = .lightGray
    forward.tintColor = .lightGray

    navigationItem.leftBarButtonItems = [back, forward]

我希望UIBarButtonItems一直处于活动状态。不只是在我与WKWebView互动之后。不,它与goBack() e.t.c.的功能无关。我已经将print("!")添加到了按钮功能中,并且在“未激活”状态下它什么也不输出。

0 个答案:

没有答案