9
votes

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):

Landscape starts out looking ok

Problems show up after autorotation (keyboard still visible, underlying content still dimmed, but the search bar has disappeared):

enter image description here

Upon rotating back to landscape, the search bar reappears, but its width is now wrong:

enter image description here

(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.

1
I've gotten a step closer by adding self.definesPresentationContext = YES; The searchBar and results controller now fit within the primary view, but the searchBar is hidden under the navigation bar.user4151918

1 Answers

5
votes

What Xcode version are you using? What iOS version on the simulator?
Tried that using Xcode 6, iOS 8.4 - That's all the code I used in the MasterVC:

class MasterViewController: UITableViewController {

    @IBAction func search(sender: UIBarButtonItem) {
        let searchController = UISearchController(searchResultsController: nil)
        searchController.hidesNavigationBarDuringPresentation = false
        presentViewController(searchController, animated: true, completion: nil)
    }
...
}

It's presented within the Master and locks the orientation of the screen! The behavior might have changed since you posted your answer.