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

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

问题描述

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

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;

(其中设置tableHeaderView属性两次是必要的,否则标题视图与第一行重叠,cf < a href =https://stackoverflow.com/a/5764819/2199136>关于SO的几个答案)

(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:

这是
奇怪的搜索栏动画视频

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

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

在我的呈现视图控制器中,我有 self.definesPresentationContext = YES; self .navigationController.navigationBar.translucent = YES; ,并且在IB中没有任何扩展边缘框是活动的(所有这些似乎都可能导致搜索演示文稿无法读取)。

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?

推荐答案

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

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.

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

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天全站免登陆