UISearchBar covered by section header

我的未来我决定 提交于 2019-12-12 03:43:05

问题


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.

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

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


回答1:


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.

Something like this:

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

...

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


来源:https://stackoverflow.com/questions/19010444/uisearchbar-covered-by-section-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!