gpt4 book ai didi

ios - 苹果手机 x : keep search bar within safe zone

转载 作者:行者123 更新时间:2023-11-28 19:29:55 26 4
gpt4 key购买 nike

升级我们的应用程序以支持 iPhone X。如何将搜索栏添加到表格 View 的标题并将其置于安全区域内?这是我们目前构建搜索栏的方式。

let searchController = UISearchController(searchResultsController: nil)
func buildSearchBar() {
self.searchController.searchResultsUpdater = self
self.searchController.hidesNavigationBarDuringPresentation = false
self.searchController.dimsBackgroundDuringPresentation = false
self.searchController.searchBar.sizeToFit()
self.tableView.tableHeaderView = searchController.searchBar

self.definesPresentationContext = true
}

最佳答案

此主题在 Building Apps for iPhone X 中明确讨论视频。 (Designing for iPhone X 也是一个不错的视频。)

最重要的是,Apple 建议使用导航 Controller 并将其显示在那里:

let searchController = UISearchController(searchResultsController: nil)
searchController.searchResultsUpdater = self
searchController.obscuresBackgroundDuringPresentation = false

if #available(iOS 11, *) {
navigationItem.searchController = searchController
searchController.isActive = true
} else {
present(searchController, animated: true)
}

(顺便说一句,即使在没有导航 Controller 的情况下,呈现搜索 Controller ,而不是将其设置为表头,也可以防止它滚出安全区域区。)

关于ios - 苹果手机 x : keep search bar within safe zone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46246779/

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