Using a universal storyboard with an adaptive UISplitViewController
user interface.
I want to present a search controller on the primary (master) side, using the following code (from the master view controller):
static NSString * const kCGISearchViewControllerID = @"SearchViewControllerID";
- (IBAction)searchButtonClicked:(UIBarButtonItem *)__unused sender {
SearchViewController *searchResultsController = [self.storyboard instantiateViewControllerWithIdentifier:kCGISearchViewControllerID];
self.searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsController];
self.searchController.searchResultsUpdater = searchResultsController;
self.searchController.hidesNavigationBarDuringPresentation = NO;
[self presentViewController:self.searchController animated:YES completion:nil];
}
It initially appears to work correctly (regardless of the starting orientation):
Problems show up after autorotation (keyboard still visible, underlying content still dimmed, but the search bar has disappeared):
Upon rotating back to landscape, the search bar reappears, but its width is now wrong:
(I've also tried placing the search controller's searchBar
in the titleView
. While the searchBar adapts correctly, the search results controller still doesn't look right.)
What am I missing to get a presented UISearchController
to animate itself properly as the UI adapts to changing size classes?
Update:
Adding self.definesPresentationContext = YES;
gets the search bar/results to appear within the primary view, but the search bar is animating under that navigation bar, and isn't visible. The other issue is that the search bar height doesn't shrink, when it rotates from portrait (which has a status bar), back to landscape.
self.definesPresentationContext = YES;
The searchBar and results controller now fit within the primary view, but the searchBar is hidden under the navigation bar. – Phrensy