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).
Use the UIViewAnimationOptionLayoutSubviews
option:
[UIView animateWithDuration:.25
delay:0
options:UIViewAnimationOptionLayoutSubviews
animations:^{
CGRect frame = searchBar.frame;
frame.size.width = newWidth;
searchBar.frame = frame;
} completion:nil
];
The problem is that some inner search bar views forcing the resize to ignore the animation.
This worked for me -
[UIView animateWithDuration:0.2 animations:^ {
[searchBar setFrame:searchBarFrame];
[searchBar setNeedsLayout];
}];
Where searchBarFrame
- is a frame you need to set (I save it before search bar resized first time)
Try this:
[UIView animateWithDuration:0.3 animations:^{
self.searchDisplayController.searchBar.frame = CGRectMake(0, 200, 320, 44);
}];