我有一个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("!")
添加到了按钮功能中,并且在“未激活”状态下它什么也不输出。