我在"UISearchDisplayDelegate协议参考“(SearchBar-animated-sample )下找到了带有范围栏的动画搜索栏的示例,这是一个视频预览:SearchBarAnimated-video
我已经检查了示例代码,但我找不到触发动画的代码。有谁知道如何制作动画吗?你必须使用UISearchBarDelegate来获得动画吗?
发布于 2014-04-08 16:23:04
为了控制UISearchBar的动画,你通过在你的头文件中扩展来实现UISearchDisplayController的委托。代表名单如下;
- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller
{
[UIView beginAnimations:nil context:NULL];
self.searchDisplayController.searchBar.showsScopeBar = NO;
CGRect headerViewFrame = self.searchDisplayController.searchBar.frame;
headerViewFrame.origin.y -= 54.0f;
self.searchDisplayController.searchBar.frame = headerViewFrame;
CGRect tableViewFrame = self.tableView.frame;
tableViewFrame.origin.y -= 54.0f;
self.tableView.frame = tableViewFrame;
[UIView commitAnimations];
}
-(void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller
{
[UIView beginAnimations:nil context:NULL];
CGRect headerViewFrame = self.searchDisplayController.searchBar.frame;
headerViewFrame.origin.y += 54.0f;
self.searchDisplayController.searchBar.frame = headerViewFrame;
CGRect tableViewFrame = self.tableView.frame;
tableViewFrame.origin.y += 54.0f;
self.tableView.frame = tableViewFrame;
[UIView commitAnimations];
}发布于 2011-09-25 19:09:30
它直接内置到了UISearchBar中。Apple为你做了这件事,你不需要自己调用任何方法。
基本上,从你设置搜索栏的scopeButtonTitles属性的那一刻起,苹果就会对范围栏进行动画处理。
发布于 2012-05-11 14:09:40
我发现这个问题的答案更有用,尽管它不会自动将搜索栏转换到视图的顶部。
How do you hide/show UISearchBar's scope bar with animation?
https://stackoverflow.com/questions/7545106
复制相似问题