UISearchDisplayController with displaysSearchBarInNavigationBar pushes result view down with navigationBar.translucent = false
Just enabled "Under Opaque Bars " in the storyboard for your view controller or if you like to code.Then add the below lines.Your good :)
self.edgesForExtendedLayout = UIRectEdgeAll;self.extendedLayoutIncludesOpaqueBars = YES;
I had the same issue and I've fixed in this way:
- Subclass UISearchDisplayController to have the UISearchBar in the NavigationBar for iOS 6 and 7. I've overwrite:
-(void)setActive:(BOOL)visible animated:(BOOL)animated { if (SYSTEM_VERSION_LESS_THAN(@"7")) { if(self.active == visible) return; [self.searchContentsController.navigationController setNavigationBarHidden:NO animated:NO]; if (visible) { [self.searchBar becomeFirstResponder]; } else { [self.searchBar resignFirstResponder]; } } else { self.searchContentsController.view.frame = CGRectMake(0, 0, kCurrentScreenWidth, kCurrentScreenHeight); [super setActive:visible animated:animated]; } }
2.In the UISearchDisplayDelegate I've added this:
- (void) searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView { // iOS7 Hack if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7")) { controller.searchResultsTableView.contentInset = UIEdgeInsetsMake(0.f, 0.f, 0.f, 0.f); } } - (BOOL) searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString { // -- iOS 7 Hack if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7")) { controller.searchResultsTableView.frame = CGRectMake(0, 64, kCurrentScreenWidth, kCurrentScreenHeight-64); [controller.searchContentsController.view setNeedsLayout]; } }
I had the same issue and after hours of searching for an answer, I decided to look through the view hierarchy. It seems that the superview of the searchBar, which is also the dimmed view, has a y origin of 64 and a height of 504, which is not populating the whole screen. Not sure why it's like that. Nevertheless, I ended up setting the y to 0 and it's height to the screen height. After which, I set its y back to the original value, or else your content table view will be distorted. It's not the best solution, but it's better than nothing. Hope this helps you.
- (void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller { self.savedSearchTerm = nil; UIView *dimmedView = controller.searchBar.superview; CGRect frame = dimmedView.frame; frame.origin.y = 64; dimmedView.frame = frame; [self.tableView reloadData];}- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller { UIView *dimmedView = controller.searchBar.superview; CGRect frame = dimmedView.frame; frame.origin.y = 0; frame.size.height = 568; dimmedView.frame = frame;}