我要检测搜索栏是否处于活动状态,以便单击同一搜索按钮,它将有条件地打开或关闭搜索栏
我尝试了searchBar.isHidden,但是显然这不是要走的路。
@objc func Search(sender: UIButton) {
if let navigationController = self.navigationController {
let searchBarObject = SearchBar()
let searchBar = searchBarObject.createSearchBar(width: navigationController.navigationBar.frame.width, height: navigationController.navigationBar.frame.height)
searchBar.showsCancelButton = true
searchBar.delegate = self
if searchBar.isHidden {
searchBar.becomeFirstResponder()
view.addSubview(searchBar)
} else {
func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
searchBar.text = nil
searchBar.showsCancelButton = false
searchBar.isHidden = true
}
}
}
sender.pulsate()
}
isHidden是不正确的,但我不知道该怎么办。