Ios 在modalPresentationStyle中快速隐藏UIView
我有一个Ios 在modalPresentationStyle中快速隐藏UIView,ios,swift,Ios,Swift,我有一个UIViewController作为modalPresentationStyle,其中有一个TextView和一个按钮(该按钮扩展了一个UIView,其中有一个搜索栏)。我现在的问题是我尝试了,搜索栏的UIView在我再次按下时关闭,我已经尝试找到解决方案,但不幸的是没有成功 @IBAction func showSearchbar(_ sender: UIBarButtonItem) { let searchbarView = UIView(frame: CGRect(x:
UIViewController
作为modalPresentationStyle
,其中有一个TextView
和一个按钮(该按钮扩展了一个UIView,其中有一个搜索栏
)。我现在的问题是我尝试了,搜索栏
的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)
}
}
在搜索栏/视图展开之前
搜索栏/视图展开后
好的,伙计们,我解决了问题,我没有全局设置UISearchbar和UIView的变量,因此UIView没有消失。你能发布你的屏幕吗?好的,是因为隐藏了searchbarView才添加的。或者因为没有再次显示它(if-else语句)。我也这么认为,但问题是UIView根本没有消失。如果我按下按钮,UITextView中的文本会上下移动,这样可以很好地工作,但我不明白,为什么UIView没有隐藏。