ios - 设置内容偏移时iOS7中的搜索栏半隐藏

标签 ios objective-c uitableview ios7 uisearchbar

我在导航 Controller 中有一个 TableView Controller ,在 viewDidLoad 我向 TableView 标题添加了一些 View :

//Build up master container view with search bar and another view that has buttons
...

//Set this as the table header
self.tableView.tableHeaderView = masterHeaderContainerView;

如果此时我什么都不做,我从上到下的 View 看起来像

导航栏,
搜索栏,
带有按钮的操作栏,
表格 View 单元格...
https://www.dropbox.com/s/mwhipz5qpa9duzw/filterAndActions.PNG

但是,我想隐藏导航栏下的搜索栏,所以我在viewWillAppear中设置了表格 View 的内容偏移量
self.tableView.contentOffset = CGPointMake(0, self.searchBar.frame.size.height);

在 iOS 6 上这工作正常,但在 iOS 7 上,当我向下滚动以显示搜索栏时,它消失了,它应该是一个空白区域。

可能会为问题提供线索的是,如果我将内容偏移量硬编码为 22(搜索栏高度的一半),然后向下滚动,则搜索栏已被看起来像背景的东西隐藏了一半。

https://www.dropbox.com/s/jm1vro769jfhpy8/halfFilterBar.PNG

所以我设置内容偏移量的量就是搜索栏被覆盖的量。有什么想法可能会在这里发生吗?

目标是有一个像邮件应用程序一样的过滤器栏,当 View 首次出现时,它隐藏在导航栏下,但可以通过向下滚动来显示。

我正在以编程方式构建搜索栏和搜索显示 Controller ,因为 View 没有 xibs/storyboard,它是标准的 UITableViewController 子类。
UISearchBar *aSearchBar = [[UISearchBar alloc] initWithFrame:CGRectZero];
UISearchDisplayController *aSearchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:aSearchBar contentsController:self];
aSearchBar.frame = ...

最佳答案

您应该设置为在 iOS 7 中获得预期的行为

self.edgesForExtendedLayout = UIRectEdgeNone;

关于ios - 设置内容偏移时iOS7中的搜索栏半隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19813466/

相关文章:

ios - 来自 native 应用程序的 Instagram API OAuth

ios - 使用 Realm,我应该使用 List 对象还是 Results 对象作为 UITableView 的数据源?

ios - UITableViewCell 选中的按钮在滚动 UITableView 时变为未选中状态

ios - swift spritekit 随着游戏时间的推移增加重力?

ios - 更改以编程方式创建的 UISearchBar 的字体

ios - 来自 iOS 的 Firebase Analytics 事件未显示

ios - UITextField 最多可容纳小数点前 10 个数字和小数点后最多三个数字

iphone - 如何在 iPhone 编程中用逗号格式化数字

ios - 如何解决 NULL cString 崩溃

iphone - 将 uisearchDisplayController TableView 样式更改为分组?