UISearchController很难受

时间:2017-10-05 23:15:25

标签: ios swift uisearchcontroller

我遇到了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

我已经尝试过许多方法来解决这个问题。我想知道我是否误解了之前的建议。欢迎任何建议。

1 个答案:

答案 0 :(得分:0)

我有同样的问题。如果您的导航栏不是半透明的,请尝试将其放在viewDidLoad中:

 extendedLayoutIncludesOpaqueBars = true