【发布时间】:2018-07-09 21:23:17
【问题描述】:
我遇到了 UISearchController 的问题。有一些关于 iOS 11 中行为不稳定的报告,但这些建议都没有解决我的问题。
导航栏隐藏在我的应用程序中,所以我只想将搜索栏放在主屏幕上的两个按钮之间。我将 UIView 放在故事板中作为搜索栏的超级视图。当激活结果控制器是一个直接的 UITableViewController。
应用启动时,一切就位。当我访问搜索栏时,它位于屏幕顶部,而将其父视图留在后面。一切正常,但是当我隐藏表格视图时,搜索栏实际比它开始时要低一些。这是设置代码:
let locationSearchTable = storyboard!.instantiateViewController(withIdentifier: "LocationSearchTable") as! LocationSearchTable
searchController = UISearchController(searchResultsController: locationSearchTable)
searchController.searchResultsUpdater = locationSearchTable
searchController.delegate = self
locationSearchTable.mapView = mapView
locationSearchTable.handleMapSearchDelegate = self
locationTableController = locationSearchTable
let searchBar = searchController!.searchBar
//searchBar.searchBarStyle = UISearchBarStyle.prominent
searchBar.sizeToFit()
searchBar.placeholder = "Search..."
searchViewHolder.addSubview(searchBar)
searchBar.frame = searchViewHolder.bounds
searchBar.autoresizingMask = [.flexibleWidth, .flexibleHeight]
searchController.dimsBackgroundDuringPresentation = true
definesPresentationContext = false
我尝试了很多很多方法来解决这个问题。我想知道我是否误解了之前的建议。欢迎任何建议。
【问题讨论】:
标签: ios swift uisearchcontroller