UITearchBar位于UITableView的顶部,它可以隐藏但保持接近UINavigationBar [英] UISearchBar on the top of UITableView which can hide but stay close to UINavigationBar

查看:119
本文介绍了UITearchBar位于UITableView的顶部,它可以隐藏但保持接近UINavigationBar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的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 适合顶部,而不是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设置为autoresize,它将会扩展。

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.

编辑:基本上是你的问题,答案中有一些代码。-the-uitableview-like-game-center>这个问题

这篇关于UITearchBar位于UITableView的顶部,它可以隐藏但保持接近UINavigationBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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