4

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!

Zoltan Krix
  • 83
  • 1
  • 6
  • Did You solve this issue I have the same problem and opened another question --> http://stackoverflow.com/questions/19467945/ios7-uisearchbar-animation-issue – luca Nov 05 '13 at 08:39
  • No, I ended up using the displaysSearchBarInNavigationBar method and putting the searchbar into the navigationbar. It's not exactly what I was going for but it will do the trick. If you find a solution could you link it as an anwser here? Thanks – Zoltan Krix Nov 06 '13 at 10:26

3 Answers3

2

I found that

self.navigationController.navigationBar.translucent = YES;

made my animation less buggy

Adam Johns
  • 35,397
  • 25
  • 123
  • 176
  • this worked for me, although annoying that i have to compensate for the color change. – Ken Mar 11 '15 at 05:25
1

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

ryback smith
  • 41
  • 2
  • 4
  • Yes I think it is a bug too. I saw that example project and yes it has a similar problem too. I couldn't figure out a way to work around it. I ended up using the displaysSearchBarInNavigationBar method and putting the searchbar into the navigationbar. It's not exactly what I was going for but it will do the trick. I hope they will fix it soon or someone finds a way to fix it. – Zoltan Krix Oct 12 '13 at 21:00
  • 3
    I found problem with IOS 7, you have to set edgesForExtendedLayout like: self.edgesForExtendedLayout = UIRectEdgeNone; – ryback smith Nov 09 '13 at 12:04
  • It's better with this but the animation still looks buggy. – Zoltan Krix Nov 10 '13 at 13:16
  • This made my animation correct, but the translucency of the navbar is taken away, so the color doesn't match the other view controllers. Maybe using this on all view controllers to keep consistency in the color would work – Jonathan Brown May 22 '14 at 19:19
-1

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.

jeswang
  • 1,017
  • 14
  • 26