ios - 如何让 UISearchController 开始隐藏?

标签 ios objective-c uisearchbar uisearchcontroller

我使用以下方法将 UISearchController 添加到我的代码中:

self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.searchBar.scopeButtonTitles = @[];
self.searchController.searchBar.delegate = self;

self.tableView.tableHeaderView = self.searchController.searchBar;
[self.searchController.searchBar sizeToFit];
self.definesPresentationContext = YES;

这将创建我的搜索 Controller 并将其添加到我的 tableView 的顶部。令人讨厌的是,它开始可见:

enter image description here

我可以通过在导航栏下向上滑动它来隐藏它,这表明代码的底层功能正在运行,但我无法让它开始隐藏,所以我可以将它向下滑动。

我试过调整边缘插入,我试过将导航栏设置为半透明,我试过在线浏览搜索栏教程,但似乎没有任何东西可以解决这个问题。

非常欢迎任何帮助

最佳答案

您是否尝试设置表格 View 的内容偏移量?

[self.tableView setContentOffset:CGPointMake(0, self.searchController.searchBar.frame.size.height) animated:NO];

关于ios - 如何让 UISearchController 开始隐藏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30666279/

相关文章:

ios - 带有 ios8 的 AVSpeechSynthesizer

ios - 推送通知不适用于 iOS9 及更高版本

ios - 当搜索栏具有焦点时,UISearchController 不会尊重隐藏的状态栏

ios - 在底层 ViewController 中禁用 UIGestureRecognizers

ios - 在起点画一个矩形,然后按照我的 Action 在 Swift 中结束手势

ios - 在 objective-c 中翻转缩放和旋转的 uiview

iphone - UISearchBar 和 UINavigationItem

uitextfield - 如何使用 UICollectionView 提供 Search-As-You-Type 过滤?

objective-c - Objective-C : Displaying Array Elements

objective-c - 多次处理潜在的大型 STDIN 数据