问题描述
我想在我的 UITableView 顶部有一个 UISearchBar,当您向下滚动时它隐藏:答案很简单,我只需要将它添加到我的表格视图标题中,如下所示:
I would like to have a UISearchBar on the top of my UITableView which hides when you scroll down: The answer is easy, I just need to add it on my table view header like this:
UISearchBar *search = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 45)];
self.tableView.tableHeaderView = search;
[search release];
但问题是,当您向上滚动 UISearchBar 适合 UITableView 的顶部,而不是 UINavigationBar 的顶部.更清楚地说,我在 Mail(不好)和 Game Center(好)中做了一个屏幕.
But the problem is that when you scroll up the UISearchBar fit to the top of the UITableView, and not the top of the UINavigationBar. To be more clear I made a screen in Mail (not good) and Game Center (good).
我想要和 Game Center 中的一样.你知道他们是怎么做到的吗?
I want the same as in Game Center. Do you have any idea how they are doing this ?
推荐答案
滚动tableview时需要自行隐藏搜索栏.所以,不要把它作为一个 UITableView 标题.您可以通过将其高度设置为零来隐藏它.这样,如果您的 tableview 设置为自动调整大小,它将展开.
You will need to hide the search bar on your own when you scroll the tableview. So, don't put it as a UITableView header. You could hide it by setting its height to zero. That way if your tableview is set to autoresize it will expand.
我会尝试将 UITableView 和 UISearchBar 作为另一个视图中的对等点.GameCenter 图像没有将搜索栏作为表格视图标题,而是将它们作为单独的子视图.
I would experiment with having the UITableView and the UISearchBar as peers within another view. The GameCenter image does not have the search bar as the table view header, rather it has them as separate subviews.
您也可以查看 UISearchDisplayController,但我认为它并没有您想要的行为.
You could also look at UISearchDisplayController but I think it doesn't quite have the behaviour that you want.
这个问题 基本上是您的问题,并且在答案中有一些代码.
This question is basically your question and has some code in the answers.
这篇关于UITableView 顶部的 UISearchBar 可以隐藏但靠近 UINavigationBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!