gpt4 book ai didi

uisearchbar - 带有 UISearchController 的透明 UIStatusBar

转载 作者:行者123 更新时间:2023-12-05 01:13:36 31 4
gpt4 key购买 nike

我正在使用以下代码来显示 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

我的问题是,当我进入搜索模式时, View 变为全屏,我可以看到 tableview 的内容与 UISearchBar 重叠,这是一个错误吗?是否可以解决此问题?

看截图

enter image description here

我的解决方案

   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()
}

最佳答案

也许您可以在搜索过程中隐藏状态栏。自定义子类应该可以工作:

class MySearchController: UISearchController {
override func prefersStatusBarHidden() -> Bool {
return true
}
}

关于uisearchbar - 带有 UISearchController 的透明 UIStatusBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28449246/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com