gpt4 book ai didi

swift - 更新到 iOS 11 后,我的搜索栏表现很奇怪

转载 作者:行者123 更新时间:2023-11-30 12:09:19 26 4
gpt4 key购买 nike

更新到 iOS11 后,我的搜索栏行为非常奇怪。激活后,它会跳转到屏幕顶部。它像以前一样正常工作,但我当然希望它保持在原位。我通过谷歌搜索这种行为尝试了很多解决方案,但没有任何帮助。有人有同样的问题吗?您采取了什么措施来解决这个问题?

searchBar in place

searchBar jumped to top

var searchController: UISearchController!


override func viewDidLoad() {
super.viewDidLoad()
// Setup the Search Controller
searchController = UISearchController(searchResultsController: nil)
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
searchController.hidesNavigationBarDuringPresentation = false
searchController.searchBar.preservesSuperviewLayoutMargins = true
searchController.obscuresBackgroundDuringPresentation = false
searchController.searchBar.sizeToFit()
walkaboutTableView.tableHeaderView = searchController.searchBar
searchController.searchBar.barTintColor = matildaLightBlue
searchController.searchBar.clipsToBounds = true
searchController.searchBar.layer.borderWidth = 2
searchController.searchBar.layer.borderColor = UIColor.black.cgColor
}

最佳答案

将搜索 Controller 实例添加到导航项而不是表标题 View 中可以帮助我解决项目中的类似问题。

if #available(iOS 11, *) {
navigationItem.searchController = searchController
} else {
tableView.tableHeaderView = searchController.searchBar
}

navigationItem.searchController

navigationItem.hidesSearchBarWhenScrolling

关于swift - 更新到 iOS 11 后,我的搜索栏表现很奇怪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46261790/

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