部分标题覆盖的 UISearchBar [英] UISearchBar covered by section header

查看:27
本文介绍了部分标题覆盖的 UISearchBar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 searchBar 作为在故事板中创建的 tableViewHeader 的一部分显示.但是,我想在某些情况下隐藏它.为此,我将 tableHeaderView.frame 的高度设置为 0.为了再次显示它,我将 tableHeaderView.frame 设置为其原始高度.当它确实显示时,它被第一节标题覆盖.下拉会随着部分标题移动搜索栏.

I have a searchBar showing as part of the tableViewHeader as created in the storyboard. However I would like to hide it under some circumstances. To accomplish this, I set the tableHeaderView.frame to a height of 0. To show it again, I set the tableHeaderView.frame to its original height. When it does show it is covered by the first section header(s). Pulling down moves the search bar along with the section header.

我尝试了 [self.searchBar sizeToFit],但没有成功.我也试过 [self.view layoutSubviews].

I tried [self.searchBar sizeToFit] after it is shown without any success. I also tried [self.view layoutSubviews].

如何防止部分标题覆盖搜索栏?(iOS 6 和 iOS 7)

How do I keep the section title from covering the search bar? (iOS 6 and iOS 7)

推荐答案

您可以将表格的内容偏移设置为搜索栏高度,而不是通过将其高度设置为零来隐藏它.这使得它基本上向上滚动到视野之外.

Instead of hiding it by setting its height to zero, you can set the table's content offset to the search bar height. This makes it basically scroll up out of view.

像这样:

@property (nonatomic, weak) IBOutlet UISearchBar* searchBar;
@property (nonatomic, weak) IBOutlet UITableView* table;

...

- (void) hideSearchBar
{
    self.table.contentOffset = CGPointMake( 0, self.searchBar.frame.size.height );  
}

这篇关于部分标题覆盖的 UISearchBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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