搜索栏使用以下代码进行动画处理:
- (IBAction)toggleSearchBar:(UIBarButtonItem *)sender{
CATransition *applicationLoadViewIn = [CATransition animation];
[applicationLoadViewIn setDuration:0.2];
[applicationLoadViewIn setType:kCATransitionPush];
[applicationLoadViewIn setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
if (self.searchBar.hidden) {
self.searchBar.hidden = NO;
[self.searchBar becomeFirstResponder];
[applicationLoadViewIn setSubtype:kCATransitionFromBottom];
[[searchBar layer] addAnimation:applicationLoadViewIn forKey:kCATransitionPush];
}else{
self.searchBar.hidden = YES;
[self.searchBar resignFirstResponder];
[applicationLoadViewIn setSubtype:kCATransitionFromTop];
[[searchBar layer] addAnimation:applicationLoadViewIn forKey:kCATransitionPush];
}
}
它工作正常,除了动画第一次运行时的滞后。有没有办法修复它?任何帮助将不胜感激:)
编辑 1
他 leftBarButton 被连接到toggleSearchBar:
行动。应用程序已加载。第一个动画是 leftBarButton 第一次点击。