No se puede animar el marco o los límites de un UISearchBar

I want to animate the position of a UISearchBar, but there's no animate effect when I change the frame or bounds property of UISearchBar(center, alpha dose animate).
It's iOS SDK 4.2, is there a bug? I'm confused...

preguntado el 09 de marzo de 12 a las 15:03

3 Respuestas

The problem is that some inner search bar views forcing the resize to ignore the animation.

Esto funcionó para mí

[UIView animateWithDuration:0.2 animations:^ {
                     [searchBar setFrame:searchBarFrame];
                     [searchBar setNeedsLayout];
                 }];

Dónde searchBarFrame - is a frame you need to set (I save it before search bar resized first time)

Respondido 10 Jul 13, 11:07

you shouldn't call layoutSubviews directly, instead it's better to call [searchBar setNeedsLayout]; [searchBar layoutIfNeeded]; - myell0w

I found that if you put the search bar to the right hand side of the navigation bar, after laying out and resizing, the search bar doesn't return to its original position. How can one solve this? - fatuhoku

Utilice el UIViewAnimationOptionLayoutSubviews opción:

[UIView animateWithDuration:.25
                      delay:0
                    options:UIViewAnimationOptionLayoutSubviews
                 animations:^{
                     CGRect frame = searchBar.frame;
                     frame.size.width = newWidth;
                     searchBar.frame = frame;
                 } completion:nil
 ];

contestado el 15 de mayo de 13 a las 23:05

Prueba esto:

[UIView animateWithDuration:0.3 animations:^{
    self.searchDisplayController.searchBar.frame = CGRectMake(0, 200, 320, 44);
}];

respondido 09 mar '12, 15:03

I tried, it didn't work. I know the method to animate a view, but the UISearchBar don't animate the right way while I'm animating the size of it. - Qué

I tried Core Animation, and got the same result. It seems that UISearchBar does some addition work when we interact with it(It automatically resize itself when I click the textarea in it). - Qué

works for me. can you show me your code? my first guess without seeing it is that you've got a bad/nil handle to your search display controller. can you throw in an NSLog to see? - danh

Please try CGRectMake(0, 0, 200, 150); - Qué

You are trying to alter the size, not the origin of the frame? Yes, it appears that the searchBar size is being constrained by the OS. I think might need to roll your own here. - danh

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.