UITableView 顶部的 UISearchBar 可以隐藏但靠近 UINavigationBar

UISearchBar on the top of UITableView which can hide but stay close to UINavigationBar(UITableView 顶部的 UISearchBar 可以隐藏但靠近 UINavigationBar)
本文介绍了UITableView 顶部的 UISearchBar 可以隐藏但靠近 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 适合 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

UIButtons at the bottom of UIScrollView not working(UIScrollView 底部的 UIButtons 不起作用)
scrollViewWillEndDragging:withVelocity:targetContentOffset: not working on the edges of a UISCrollView(scrollViewWillEndDragging:withVelocity:targetContentOffset: 不在 UISCrollView 的边缘工作)
ImageView Scaling when scrolling down(向下滚动时 ImageView 缩放)
Bounds automatically changes on UIScrollView with content insets(UIScrollView 上的边界自动更改,带有内容插图)
iOS5 UITapRecognizer for UIScrollView interfering with buttons. How to fix?(用于 UIScrollView 的 iOS5 UITapRecognizer 干扰按钮.怎么修?)
Handling scroll views with (custom, interactive) view controller presentation and dismissal(使用(自定义、交互式)视图控制器呈现和解除处理滚动视图)