Search code examples
iosobjective-cuisplitviewcontroller

Hide MasterViewController from DetailViewController in a SplitViewController


I have a SplitViewController set up with a DetailViewController and a MasterViewController. The DetailViewController contains a map and I want to place a button on the map that collapses and expands the MasterViewController. Exactly like this in Apple's App Store app:

enter image description here

Clicking on the button then gives:

enter image description here

Any ideas on how I can achieve a similar effect? Note I don't want to close the top tool bar, just the MasterViewController. Thanks!

SOLUTION

Thanks to Pravin, my final solution in the IBAction is:

if (self.splitViewController.preferredDisplayMode == UISplitViewControllerDisplayModePrimaryHidden) {
    self.splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModeAllVisible;
} else {
    self.splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryHidden;
}

[UIView animateWithDuration:0.5 animations:^ {
     [self.splitViewController.view layoutIfNeeded];
 }];

Solution

  • hide master view

    AppDelegate * appDelegateObj = (AppDelegate *)[UIApplication sharedApplication].delegate;
            UISplitViewController * splitView = appDelegateObj.splitViewObj;
            splitView.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryHidden;
            [UIView animateWithDuration:1.0 animations:^
             {
                 [spv.view layoutIfNeeded];
             }];
    
    show master view
    
    
    AppDelegate * appDelegateObj = (AppDelegate *)[UIApplication sharedApplication].delegate;
            UISplitViewController * splitView = appDelegateObj.splitViewObj;
            splitView.preferredDisplayMode = UISplitViewControllerDisplayModeAllVisible;
            [UIView animateWithDuration:1.0 animations:^
             {
                 [spv.view layoutIfNeeded];
             }];
    

    I hope it will useful for you!