Q:

Animating show/hide of master view in UISplitViewController in iOS 8

I'm using a split view in an iPad only, iOS 8 application in its standard form. (When the iPad is landscape it shows both the master and detail view; when portrait it shows the detail view full screen with a master view that slides in from the left.) Both the master and detail views are navigation view controllers where the master contains a table view controller. Selections in the master view's table change the detail view. This is all set up and working correctly.
What I'd like to do, however, is when in portrait orientation a selection made in the master view's table, the master view should animate off the screen. Secondarily, if a selection hasn't been made in the master view's table on start-up in portrait mode, I'd like to animate the master view into view.
Any guidance is appreciated.

A:

The answer is to animate the preferredDisplayMode property. To show the code is:
if (UIInterfaceOrientationIsPortrait([UIDevice currentDevice].orientation)) {
  [UIView animateWithDuration:ANIMATION_LENGTH animations:^{
    self.splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryOverlay;
  } completion:^(BOOL finished) {
    self.splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModeAutomatic;
  }];
}

and to hide the code is:
if (UIInterfaceOrientationIsPortrait([UIDevice currentDevice].orientation)) {
  [UIView animateWithDuration:ANIMATION_LENGTH animations:^{
    self.splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryHidden;
  } completion:^(BOOL finished) {
    self.splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModeAutomatic;
  }];
}

I set it back to Automatic in the completion so the split view controller can do its normal thing after the animation is completed. I also add another boolean to the show so I only show it if my detail item hasn't been set yet but I removed it from the code above since this is specific to your own code.

