[英]Why UISearchController disappears when typing on UISearchBar?
func configureSearchController() {
// Initialize and perform a minimum configuration to the search controller.
searchController = UISearchController(searchResultsController: nil)
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
searchController.searchBar.placeholder = "Search"
searchController.searchBar.delegate = self
searchController.searchBar.sizeToFit()
// Add search bar to View.
self.view.addSubview(searchController.searchBar)
searchController.searchBar.translatesAutoresizingMaskIntoConstraints = false
view.bringSubview(toFront: searchController.searchBar)
//add constraints on searchbar
view.addConstraint(NSLayoutConstraint(item: searchController.searchBar, attribute: .trailing, relatedBy: .equal, toItem: view, attribute: .trailing, multiplier: 1, constant: 0))
view.addConstraint(NSLayoutConstraint(item: searchController.searchBar, attribute: .leading, relatedBy: .equal, toItem: view, attribute: .leading, multiplier: 1, constant: 0))
view.addConstraint(NSLayoutConstraint(item: searchController.searchBar, attribute: .top, relatedBy: .equal, toItem: self.topLayoutGuide, attribute: .bottom, multiplier: 1, constant: 0))
view.addConstraint(NSLayoutConstraint(item: searchController.searchBar, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute,multiplier: 1, constant: 64))
}
So that was my code, I added a searchController searchbar as subview to a View. 这就是我的代码,我将一个searchController搜索栏添加为View的子视图。 I added constraints as well.
我也添加了约束。
Whenever I type something in the search bar, the whole thing disappears, and also the navigation bar in an animated fashion. 每当我在搜索栏中输入内容时,整个内容就会消失,导航栏也会以动画形式消失。
searchController1.hidesNavigationBarDuringPresentation = false
将以下内容添加到ViewController中
definesPresentationContext = true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.