gpt4 book ai didi

ios - UISearchController 不会关闭 iOS 8 Swift 的搜索栏和重叠

转载 作者:IT王子 更新时间:2023-10-29 05:29:59 24 4
gpt4 key购买 nike

我在使用 UISearchController 时遇到问题,如果我在搜索栏中有文本并关闭它所在的 VC,搜索栏将不会消失,只会保留在屏幕上,与其他 VC 中的所有内容重叠。然后,如果您点击取消按钮,它就会崩溃。

在 SO 上尝试了一些解决方案,但没有一个有效。 :/

self.resultSearchController = ({
let controller = UISearchController(searchResultsController: nil)
controller.searchResultsUpdater = self
controller.dimsBackgroundDuringPresentation = false
controller.hidesNavigationBarDuringPresentation = false
controller.searchBar.sizeToFit()

controller.searchBar.searchBarStyle = UISearchBarStyle.Minimal
controller.searchBar.barTintColor = UIColor(red: 243/255, green: 243/255, blue: 243/255, alpha: 1)
controller.searchBar.tintColor = UIColor.blackColor()

controller.definesPresentationContext = true
controller.edgesForExtendedLayout = UIRectEdge.None
self.tableView.contentInset = UIEdgeInsetsMake(64, 0, 0, 0)

self.tableView.tableHeaderView = controller.searchBar

return controller
})()

非常感谢对此的任何帮助!

更新:所以我找到了一个不太好的解决方案,即在 viewWillDisappear 中设置 .active = false。然而,问题是 searchBar 工件会在下一个/上一个 VC 上显示一秒钟,然后才会完全消失。

最佳答案

更改以下内容:

controller.definesPresentationContext = true

self.definesPresentationContext = true

当您将 View Controller 插入和弹出导航堆栈时,该设置还会保留搜索栏的状态。

您可以在 Apple's Documentation on UIViewController 上阅读有关 definesPresentationContext 设置的信息.

关于ios - UISearchController 不会关闭 iOS 8 Swift 的搜索栏和重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29830698/

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