3

I'm trying to add a simple animation when I resize the UISearchBar from the leftBarButtonItem. For some reason, the resize doesn't animate, although the searchBar's size is modified. However, if I try to modify the searchBar's alpha it does animate.

Here is the code

UISearchBar *baseSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 100, 40)];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:baseSearchBar];

And the animation method is:

  [UIView animateWithDuration:2.0f animations:^{
    searchBar.frame = CGRectMake(0, 0, 400, 40);
    searchBar.alpha = 0;
} completion:^(BOOL finished) {  
}];

As i said, the resize DOES work, but not animated and the animation works if I'm trying to change the alpha.

One more thing... I tried to do the same thing for the rightBarButtonItem and the animation worked..

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
           action:@selector(expandWithAnimation:)
 forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Test" forState:UIControlStateNormal];
button.frame = CGRectMake(0, 0, 50, 40);
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];

Thank you in advance

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Durican Radu
  • 1,327
  • 11
  • 12
  • possible duplicate [Can't animate the frame or bounds of a UISearchBar](http://stackoverflow.com/a/10319005/440060) – maroux May 22 '13 at 13:43
  • 1
    Thank you! I found the answer on that link. All I needed to do was [searchBar layoutSubviews]; – Durican Radu May 22 '13 at 14:15
  • possible duplicate of [Can't animate the frame or bounds of a UISearchBar](http://stackoverflow.com/questions/9636367/cant-animate-the-frame-or-bounds-of-a-uisearchbar) – rmaddy May 22 '13 at 16:29

0 Answers0