iOS 13 UISearchBar 外观和行为

标签 ios swift uisearchbar ios13

我的 UISearchBar 设置如下:

searchController.searchResultsUpdater = self
searchController.obscuresBackgroundDuringPresentation = false // Allow user to tap on results
searchController.searchBar.placeholder = "Search patients" // Placeholder
searchController.searchBar.barStyle = .blackOpaque
searchController.searchBar.tintColor = colors.text // Cancel button tint

navigationItem.searchController = searchController // Set the searchController
navigationItem.hidesSearchBarWhenScrolling = true // Auto-hide search when user scrolls

这是它在 iOS 12 上的样子:iOS 12 appearance 与 iOS 13:enter image description here iOS 13 发生了什么变化?我尝试过不同的 barStyles,并将 .isTranslucent 设置为 false - 两者都没有效果。明/暗模式也不会改变任何东西。

另一个变化是隐藏搜索栏 - 在 iOS 12 上,如果我向上滚动一点,搜索栏就会隐藏(无论表格是否填充)。在 iOS 13 中,一旦搜索栏出现(即用户向下滑动),它就无法再次隐藏。有人知道这个问题的解决办法吗?

最佳答案

我也遇到了和你类似的问题。我不知道为什么在当前的 iOS 13 中会发生这种情况,而在旧版本中却可以正常工作。但我通过将此功能添加到您的搜索栏找到了解决方案。

if #available(iOS 13.0, *) {
   searchBar.searchTextField.backgroundColor = UIColor.white
}

修复后预览:

before fixing after fixing

关于iOS 13 UISearchBar 外观和行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57927576/

相关文章:

ios - PromiseKit 后退一步

ios - 如何在 TestFlight 中拥有多个版本的应用程序?

objective-c - NSDateComponents

ios - 在 Interface Builder 中使用泛型类作为自定义 View

iphone - 不使用导航 Controller 的 UISearchController

ios - 如何对从 WebService 接收到的数据执行搜索操作?

ios - 如何保持 UISearchBar 的占位符与搜索图标左对齐

ios - 为什么 Apple 在使用 NSFileManagerDelegate 时建议使用自己的 NSFileManager?

ios - 无法链接我的计时器按钮 (Xcode)

xcode - 无法使用命令行工具运行 Swift 代码