OGeek|极客世界-中国程序员成长平台

标题: ios - UISearchController 问题 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 18:55
标题: ios - UISearchController 问题

我遇到了 UISearchController 的问题。有一些关于 iOS 11 中行为不稳定的报告,但这些建议都没有解决我的问题。

导航栏隐藏在我的应用程序中,所以我只想将搜索栏放在主屏幕上的两个按钮之间。我将 UIView 放在 Storyboard中作为搜索栏的 super View 。当激活结果 Controller 是一个直接的 UITableViewController。

应用启动时,一切就位。当我访问搜索栏时,它位于屏幕顶部,而将其父 View 留在后面。一切正常,但是当我隐藏表格 View 时,搜索栏实际比它开始时要低一些。这是设置代码:

    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

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



Best Answer-推荐答案


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

 extendedLayoutIncludesOpaqueBars = true

关于ios - UISearchController 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46596105/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4