我想实现一个搜索栏,其行为与iphone上的邮件应用程序完全相同。当导航栏和搜索栏按照邮件程序的方式向上移动时,我无法让范围栏顺利显示。在邮件应用程序中,导航栏和搜索栏向上移动以显示范围栏。我该如何实现这种动画?
我做了粗暴的事情:
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {
searchBar.scopeButtonTitles = [NSArray arrayWithObjects:@"Button",@"Titles",@"Go",@"Here",nil];
searchBar.showsScopeBar = YES;
[searchBar setShowsCancelButton:YES animated:YES];
[self.navigationController setNavigationBarHidden:YES animated:YES];
self.tableView.contentOffset = CGPointMake(0, 0);
[searchBar sizeToFit];
return YES;
}
搜索栏在我的viewdidload中分配如下:
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
searchBar.delegate = self;
self.tableView.tableHeaderView =searchBar;
[searchBar release];
在我的viewwillappear中,我偏移了表格视图以隐藏导航栏下的搜索栏:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.tableView.contentOffset = CGPointMake(0, 44);
}
谢谢!
答案 0 :(得分:0)
尝试将-setNavigationBarHidden:animated:
发送到- searchBarTextDidBeginEditing:
中的导航栏。