The search bar is animated using the following code:
- (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];
}
}
It works fine except the lag at the first run of the animation. Is there anyway to fix it? Any help will be appreciated:)
Edit 1
he leftBarButton is wired to toggleSearchBar: action. The app is loaded. The first animation is the first time the leftBarButton clicked.
Why don’t you show it off screen on loading the view controller… it’s a bit hacky but it should do the trick.