由 UISearchController 在表头视图中呈现的 UISearchBar 在活动时动画太远 [英] UISearchBar presented by UISearchController in table header view animates too far when active

查看:29
本文介绍了由 UISearchController 在表头视图中呈现的 UISearchBar 在活动时动画太远的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

<代码>...self.searchController.hidesNavigationBarDuringPresentation = NO;self.presentingTVC.tableView.tableHeaderView = self.searchController.searchBar;[self.searchController.searchBar sizeToFit];self.presentingTVC.tableView.tableHeaderView = self.searchController.searchBar;

(其中必须将 tableHeaderView 属性设置两次,否则标题视图会与第一行重叠,请参阅

如果我只使用与 UISearchController 分开的搜索栏,它在变为活动状态时不会显示相同的行为.

在我的呈现视图控制器中,我有 self.definesPresentationContext = YES;self.navigationController.navigationBar.translucent = YES;,而在 IB 中没有扩展边缘"框处于活动状态(所有似乎都是可能的事情,可能会导致搜索演示从阅读中消失).

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

解决方案

好吧,我终于为自己找到了解决方案.尽管我们的代码/故事板中很可能还有其他内容(这就是为什么这是一个很难回答的问题),但在大多数情况下,我遵循了 Apple 关于 UISearchController 的教程:(https://developer.apple.com/library/ios/samplecode/TableSearch_UISearchController/Introduction/Intro.html)

我几乎所有的代码都与他们的相同,但是在搜索栏内部单击时,我无法让搜索栏不跳转.所以我所做的是在我的故事板中检查原始表格视图和搜索结果表格视图的在不透明条下".这让搜索栏停止跳跃.

但是还有最后一个问题,即结果表视图的第一行被搜索栏隐藏了.为了解决这个问题,我在结果表视图的 viewDidLoad 方法中添加了 self.tableView.contentInset = UIEdgeInsetsMake(kHeightOfTableViewCells, 0, 0, 0);.瞧!

I am using UISearchController to present a search bar inside the header view of a tableview:

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

(where setting the tableHeaderView property twice is necessary as otherwise the header view overlaps the first row, c.f.a couple of answers on S.O. )

This is how it looks, perfectly in position when inactive:

The search bar should just stay in place when active - I don't want it to move up to hide the navigation bar. But it unexpectedly animates down, leaving a blank space between it and the navigation bar:

Here's a video of weird search bar animation

If I just use a search bar separately from UISearchController, it does not show the same behaviour when it becomes active.

In my presenting view controller, I have self.definesPresentationContext = YES; and self.navigationController.navigationBar.translucent = YES;, and in IB none of the "extend edges" boxes are active (all seemed to be possible things that could throw search presentation off, from reading around).

Does anyone know how I can stop the search bar from animating down?

解决方案

Ok so I finally figured out a solution for myself. Though it's more than likely we have other things in our code / storyboard (that's why this is a hard question to answer), for the most part I followed Apple's tutorial on UISearchController: (https://developer.apple.com/library/ios/samplecode/TableSearch_UISearchController/Introduction/Intro.html)

Just about all my code is identical to theirs, but I couldn't get the search bar to not jump when clicking inside of it. So what I did was check "under opaque bars" for both the original table view and the search results table view in my storyboard. That got the search bar to stop jumping.

But there was one last issue, which was the fact that the first row of the results table view was hidden by the search bar. In order to fix that I added self.tableView.contentInset = UIEdgeInsetsMake(kHeightOfTableViewCells, 0, 0, 0); to the viewDidLoad method of my results table view. Voila!

这篇关于由 UISearchController 在表头视图中呈现的 UISearchBar 在活动时动画太远的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆