我如何知道搜索栏是否处于活动状态?

时间:2019-06-23 07:40:13

标签: swift uisearchbar

我要检测搜索栏是否处于活动状态,以便单击同一搜索按钮,它将有条件地打开或关闭搜索栏

我尝试了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是不正确的,但我不知道该怎么办。

0 个答案:

没有答案