Unable to animate UISearchBar frame or borders

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

+4
source share
3 answers

The problem is that some inner lines in the search bar cause the resize to ignore the animation.

It worked for me -

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

Where searchBarFrame is the frame to set (I save it before the search bar changes for the first time)

+9
source

Use the UIViewAnimationOptionLayoutSubviews parameter:

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

Try the following:

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

Source: https://habr.com/ru/post/1400595/


All Articles