UISearchBar Not shifting up

3 Solutions Collect From Internet About “UISearchBar Not shifting up”

The searchbar doesn’t actually move in the ‘push-up’ animation. Rather it stays in place while the navbar goes up, thus pulling the rest of the view with it. You should be able to move the search bar manually in code by registering as its delegate (UISearchBarDelegate) and responding to these calls.

#pragma mark - UISearchBarDelegate Methods
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {
    //move the search bar up to the correct location eg
    [UIView animateWithDuration:.4
                 animations:^{ 
                     searchBar.frame = CGRectMake(searchBar.frame.origin.x,
                                                  0,
                                                  searchBar.frame.size.width,
                                                  searchBar.frame.size.height);
                 } 
                 completion:^(BOOL finished){
                     //whatever else you may need to do
                 }];
}

- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar {
    //move the search bar down to the correct location eg
    [UIView animateWithDuration:.4
                 animations:^{ 
                     searchBar.frame = CGRectMake(searchBar.frame.origin.x,
                                                  /*SearchBar original Y*/,
                                                  searchBar.frame.size.width,
                                                  searchBar.frame.size.height);
                 } 
                 completion:^(BOOL finished){
                     //whatever else you may need to do
                 }];
}

The best way to implement an UISearchBar and an UISearchDisplayController following Apple guidelines is looking at the example called TableSearch, the description says:

Demonstrates how to search the contents of a UITableView using
UISearchBar and UISearchDisplayController, effectively filtering in
and out the contents of that table. If an iPhone/iPod Touch
application has large amounts of table data, this sample shows how to
filter it down to a manageable amount if memory usage is a concern or
you just want users to scroll through less table content.

I hope this helps you.

In the first image of your question, you are showing a UISearchDisplayController being used. In order to achieve that exact animation, you will need to use a UISearchDisplayController and modify it’s UISearchBar to look like the custom one you made. You can drag a UISearchDisplayController over in Interface Builder and then use code to change it’s searchBar property.

self.searchDisplayController.searchbar will be what you modify if you have everything hooked up correctly in Interface BUilder.