I have a problem with UISearchBar animation.
The animation is buggy when the statusbar is on. Otherwise it is okay. I created the tableview and the searchbar programatically. The uisearchbar is in the headerview of a tableview. It's important that it stays that way. I know its working okay when you use the storyboard.
I created a very basic sample project as I think this is the easiest way to show you the problem. I have spent several hours to find the solution but I just can't figure it out. Any help would be greatly appreciated.
Here's a link to the sample project: SearchBarProject!
I found that
self.navigationController.navigationBar.translucent = YES;
made my animation less buggy
I thinks this is IOS 7 bug. There is an uitableview search example application provided by Apple. And it has same problem while finishing editing search bar. With IOS 6 there is no any problem
Just add a sublayer to the UISearchBar and change the view's background color will make the animation almost perfect
- (void) searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller {
self.view.backgroundColor = RGB(199,199,204);
self.fixSearchAnimation = [[UIView alloc] initWithFrame:CGRectMake(0, -20,320, 40)];
self.fixSearchAnimation.backgroundColor = RGB(199,199,204);
[self.searchController.searchBar addSubview:self.fixSearchAnimation];
[self.searchController.searchBar sendSubviewToBack:self.fixSearchAnimation];
}
- (void) searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller {
self.view.backgroundColor = [UIColor whiteColor];
[self.fixSearchAnimation removeFromSuperview];
}
in slow mode, you can still see a tiny line between the searchbar origin subviews and the new view, but it's not very noticeable for a user, and if that disturb you, you can dig into the view hierarchical of UISearchbar and put the view in the right position.
来源:https://stackoverflow.com/questions/19192113/uisearchbar-with-statusbar-animation-transition-bug-ios7