ios - UISearchController 在表头 View 中呈现的 UISearchBar 在事件时动画太远

标签 ios uitableview ios8 uisearchbar uisearchcontroller

我正在使用 UISearchController 在 tableview 的标题 View 中显示一个搜索栏:

...
self.searchController.hidesNavigationBarDuringPresentation = NO;            
self.presentingTVC.tableView.tableHeaderView = self.searchController.searchBar;
[self.searchController.searchBar sizeToFit];
self.presentingTVC.tableView.tableHeaderView = self.searchController.searchBar;

(必须将 tableHeaderView 属性设置两次,否则标题 View 会与第一行重叠,参见 a couple of answers on S.O.)

这是它的样子,在不活动时完美地就位: Inactive search bar in correct position

搜索栏应该在事件时保持原位 - 我不希望它向上移动以隐藏导航栏。但它意外地向下动画,在它和导航栏之间留下一个空白:

Screenshot showing search bar animated too far down

这是一个 video of weird search bar animation

如果我只是使用与 UISearchController 分开的搜索栏,它在激活时不会显示相同的行为。

在我的呈现 View Controller 中,我有 self.definesPresentationContext = YES;self.navigationController.navigationBar.translucent = YES;,而在 IB 中没有“extend edges”框处于事件状态(所有这些似乎都是可能会导致搜索显示中断,无法阅读)。

有谁知道如何阻止搜索栏向下动画?

最佳答案

老问题,但我能够通过设置来解决这个问题

self.extendedLayoutIncludesOpaqueBars = YES;

在我的 View Controller 上。我认为问题是由于导航栏不透明,但在搜索 Controller 上将 hidesNavigationBarDuringPresentation 设置为 NO,导致搜索栏在聚焦时定位不正确。

关于ios - UISearchController 在表头 View 中呈现的 UISearchBar 在事件时动画太远,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28326269/

相关文章:

ios - 关于 Realm 数据库中的事务

ios - 如何强制 NSLocalizedString 使用特定语言

ios - 我的 UITableView 中的自定义标题 View 在底部绘制了额外的线

ios - 在我的 uiwebview 开始加载时添加自定义背景图像(使用 Swift)

ios - 在 Parse.com 上处理音频

ios - 如何在点击另一行时取消选择一行?

objective-c - 如何在第一次打开时滚动到 UITableView 中的一行

ios - 如何重置 iOS 中的 uitableViewCell 内容?

ios - 如何在 UIScrollVIew 中只加载可见的 subview

swift - 滑动侧边栏菜单 IOS 8 Swift