用户点击 SearchBar 时如何使 TableView 不透明

How to opacity TableView when user tapped on SearchBar

我是一名新 IOS 程序员。我想构建一个与调用 "Phone" 的默认 IOS 应用程序非常相似的应用程序,对于该应用程序,我只关注联系人,我已经实现了 searchBar。对于我的问题是,当用户点击 searchBar.

时,我想让视图变得不透明

到目前为止我尝试了什么 Here is detail of my output

这是我的预期Here is detail of my expectation.

另外一部分是当用户点击那个深色视图时,键盘也应该被关闭。

如何在用户向上滚动时让 searchBar 停留在导航栏上?

感谢您的帮助<3

你应该使用dimsBackgroundDuringPresentation

let searchController = UISearchController()
searchController.dimsBackgroundDuringPresentation = true
searchController.hidesNavigationBarDuringPresentation = false