如何开发iOS个类似AppStore搜索功能的app?

How to develop iOS app just like AppStore's searching function?

我想开发一个简单的词典应用程序,它类似于 iPhone 上 AppStore 的搜索选项卡:

  1. 第一个屏幕顶部有一个SeachBar,底部是"History words"(例如AppStore上的"Trending Searches")。

当用户触摸搜索栏时,底部视图是灰色的。触摸灰色区域离开搜索文本框,我的用户可以点击其中一个历史单词。

  1. 如果 he/she 在 SearchBar 上键入,建议词列表出现并且 he/she 可以单击一个词以查看其定义,SearchBar 包含该词(我不希望我的用户有转到第二个视图查看单词的定义,因为如果是这样,他们必须单击“后退”按钮以触摸并在“搜索”文本框中键入。很可能,我的应用程序只有 1 ViewController).

我知道如何使用 SearchBar 和 TableView 来显示建议词列表,但不知道如何实现其他功能:

感谢阅读,请告诉我一些关键字,解决以上三个问题的线索。

非常感谢!

使用 UISearchController 创建您想要的页面。

它有 dimsBackgroundDuringPresentation 属性 可以在用户输入时使背景视图变灰。

它有- (instancetype)initWithSearchResultsController:(UIViewController *)searchResultsController方法。您可以使用 resultsController 初始化 UISearchController。对于结果,你可以做任何你想做的事情。

最后,您可以设置自定义视图以查看 "History words" 到 UISearchController