我想防止 UISearchController 中的键盘消失。 我正在为 searchResultsController 使用自定义视图,当我上下滚动键盘显示/隐藏时,它会滚动结果视图。 有什么想法可以解决这个问题吗?
您应该将此代码添加到您的自定义 ResultController(UIScrollViewController 或 UITableViewController 或 UICollectionViewController)
// We use this to disable native behaviour of searchController
override func contentScrollView(for edge: NSDirectionalRectEdge) -> UIScrollView? {
return UIScrollView()
}
基本上您返回的是一个空卷轴,因此系统不会引用您的自定义卷轴。本质上该值为零,在这种情况下系统将搜索最近的滚动视图。因此,要禁用它,我们需要返回一个空的。
为搜索控制器设置searchControllerObservedScrollView,如下所示:
searchController.searchControllerObservedScrollView = (resultController as? UICollectionviewController)?.collectionView