我使用以下代码来显示一个UISearchBar。
我的问题是当我进入搜索模式时,视图变成了全屏状态,我可以看到TableView的内容与UISearchBar重叠在一起,这是一个bug吗?有没有解决这个问题的方法?
请查看截图。
我的解决方案:
searchController = UISearchController(searchResultsController: resultsTableViewController)
searchController?.searchResultsUpdater = self
searchController?.searchBar.sizeToFit()
searchController?.searchBar.backgroundColor = UIColor.whiteColor()
searchController?.searchBar.searchBarStyle = UISearchBarStyle.Minimal
self.tableView?.tableHeaderView = searchController?.searchBar
searchController?.delegate = self
searchController?.dimsBackgroundDuringPresentation = false
searchController?.searchBar.delegate = self
definesPresentationContext = true
我的问题是当我进入搜索模式时,视图变成了全屏状态,我可以看到TableView的内容与UISearchBar重叠在一起,这是一个bug吗?有没有解决这个问题的方法?
请查看截图。
我的解决方案:
func willPresentSearchController(searchController: UISearchController) {
topBarView = UIView(frame: CGRectMake(0.0, 0.0, self.view.frame.size.width, 20.0))
topBarView?.backgroundColor = UIColor.whiteColor()
AppDelegate.sharedAppDelegate().window?.rootViewController?.view.addSubview(topBarView!)
}
func willDismissSearchController(searchController: UISearchController) {
topBarView?.removeFromSuperview()
}
self.automaticallyAdjustsScrollViewInsets = YES;
- orkenstein