How to make UISearchBar in UINavigationBar resize only left margin using block animation?

I am trying to duplicate UISearchBar animations in mobile Safari. Instead of moving only the left margin, UISearchBar expands the screen and then “jumps” to the desired location. The contraction is also uneven. How can I make this animation, even as a UISearchBar in mobile safari?

searchBar = [[[UISearchBar alloc] initWithFrame:CGRectMake(0,0,175,44)] autorelease];
searchBar.delegate = self;
searchBar.showsCancelButton = YES;
searchBar.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth;
UIBarButtonItem *customBarItemRight = [[[UIBarButtonItem alloc] initWithCustomView:searchBar] autorelease];
tabBarController.navigationItem.rightBarButtonItem = customBarItemRight;


- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
searchDisplayController.searchResultsTableView.hidden = NO;
[UIView animateWithDuration:.3
animations:^ {
CGRect newBounds = searchBar.bounds;
newBounds.size.width = 350;
searchBar.bounds = newBounds;
}];
[searchDisplayController setActive:YES animated:YES];
}
+3
source share
1 answer

You should not use the UISearchDisplayController for this, you need to implement animations for your custom view controller.

0
source

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


All Articles