我有一个UIViewController
作为modalPresentationStyle
,其中有一个TextView
和一个Button(Button扩展了一个UIView,其中SearchBar
在其中)。现在的问题是,我尝试尝试再次按下SearchBar
的UIView时关闭它,我已经尝试找到一种解决方案,但不幸的是没有成功。
@IBAction func showSearchbar(_ sender: UIBarButtonItem) {
let searchbarView = UIView(frame: CGRect(x: 0, y: 44, width: self.view.frame.width, height: 50))
searchbarView.backgroundColor = UIColor.gray
textNotiz.textContainerInset = UIEdgeInsets(top: 50, left: 0, bottom: 0, right: 0)
self.view.addSubview(searchbarView)
let searchBar:UISearchBar = UISearchBar(frame: CGRect(x: 0, y: 0, width: searchbarView.frame.width, height: 50))
searchBar.delegate = self
searchBar.searchBarStyle = UISearchBarStyle.prominent
searchBar.placeholder = " Search..."
searchBar.sizeToFit()
searchBar.isTranslucent = false
searchBar.backgroundColor = UIColor.lightGray
searchbarView.addSubview(searchBar)
if isExpanded == false {
isExpanded = true
} else {
isExpanded = false
searchbarView.isHidden = true
textNotiz.textContainerInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
}
}
答案 0 :(得分:0)
好的,我解决了这个问题,我没有全局设置UISearchbar和UIView的变量,因此UIView不会消失。