【发布时间】:2015-02-11 07:58:40
【问题描述】:
我正在使用以下代码来显示 UISearchBar
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 重叠,这是一个错误,任何解决此问题的方法吗?
看截图
我的解决方案
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; -
这个不行
-
“红名单”是章节标题?
-
上面没有我的简单解决方案
-
您以一种粗略的方式操作子视图。你想达到什么目标?
标签: uisearchbar uistatusbar uisearchcontroller