您只需要在单击搜索图标时更改 UISearchBar 的框架即可显示它。
见
最初,当你不显示 UISearchBar 时,你应该以这种方式设置 Frame。
将UISearchBar的Frame设置在ViewFrame的外侧。
thisSearchBar.frame = CGRectMake(0.0, -50.0, searchBarWidth, searchBarHeight)]; 在viewDidLoad 方法中
单击搜索图标以显示 UISearchBar
- (void)showSearchBar{
[UIView animateWithDuration:0.2f delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
thisSearchBar.frame = CGRectMake(0.0, 50, searchBarWidth, searchBarHeight)];
}completion:^(BOOL finished)
{
}];
}
你又完成了 SearchBar 的工作,调用了用动画设置 Searchbar 的框架
- (void)hideSearchBar{
[UIView animateWithDuration:0.2f delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
thisSearchBar.frame = CGRectMake(0.0, -50, searchBarWidth, searchBarHeight)];
}completion:^(BOOL finished)
{
}];
}