我在导航 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/