Hiding UISplitViewController overlay in portrait

Having adopted the new UISplitViewController , I am trying to change the default behavior that occurs when using the UISplitViewControllerDisplayModeAutomatic mode.

When working on a portrait, I want the main overlay to be hidden when the user invokes clicking on the side of the part. By default, the overlay remains on the screen until the user navigates to the part.

I tried using the delegate as follows:

 - (BOOL)splitViewController:(UISplitViewController *)splitViewController showDetailViewController:(UIViewController *)vc sender:(id)sender { if (splitViewController.displayMode == UISplitViewControllerDisplayModePrimaryOverlay) { [UIView animateWithDuration:0.3 animations:^{ splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryHidden; }]; } return NO; } 

This gives me the desired behavior in the portrait, but it violates the landscape mode (which I want to conduct as UISplitViewControllerDisplayModeAllVisible ). If you click and then rotate the device, the left side is still hidden (as expected). I canโ€™t find an appriprite place to connect, to re-set my preferred rotation mode to show the left side (since the tag collections cannot be used to tell the landscape and portrait on the iPad).

How can I manually trigger an overlay dismissal?

Dupe Note: iOS8 completely changed the UISplitViewController , so all the other SO answers until June 14 are probably erroneous (and I broke through many of them, just incase)

+7
ios ios8 ios-universal-app screen-rotation uisplitviewcontroller
source share
5 answers

I had the same problem as you. I am doing this on the Xamarin touchscreen platform, but I think the result will be the same.

Like what LaborEtArs said, move your code to the prepareForSegue:sender: method of the main view controller. Then just set the mode to automatic after hiding it:

 if (splitViewController.displayMode == UISplitViewControllerDisplayModePrimaryOverlay) { splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryHidden; splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModeAutomatic; } 

After that, he no longer violates the landscape regime.

+5
source share

Just put your code (without return NO; ) in the controllers of the main view prepareForSegue:sender: or tableView:didSelectRowAtIndexPath: It works great there!

+3
source share

In addition to LaborEtArs tips on making animations in prepareForSegue:sender: or tableView:didSelectRowAtIndexPath: if your application usually has splitViewController:preferredDisplayMode set to UISplitViewControllerDisplayModeAutomatic , just use the animateWithDuration: method with the completion handler to restore display

 if (splitViewController.displayMode == UISplitViewControllerDisplayModePrimaryOverlay) { [UIView animateWithDuration:0.3 animations:^{ splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryHidden; } completion:^(BOOL finished){ splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModeAutomatic; }]; } 
+1
source share

Here is the Swift version:

 if (self.splitViewController?.displayMode == UISplitViewControllerDisplayMode.PrimaryOverlay){ splitViewController?.preferredDisplayMode = UISplitViewControllerDisplayMode.PrimaryHidden splitViewController?.preferredDisplayMode = UISplitViewControllerDisplayMode.Automatic } else { println(self.splitViewController?.displayMode) } 

Posted in prepareForSegue

0
source share
 @implementation SplitProductView - (void)viewDidLoad { [super viewDidLoad]; self.delegate = self; } - (void)viewWillAppear:(BOOL)animated{ [self resetSplit:[[UIApplication sharedApplication] statusBarOrientation]]; [super viewWillAppear:animated]; } -(void)resetSplit :(UIInterfaceOrientation)toInterfaceOrientation { //TODOX:iphone if (isPad) { if(UIInterfaceOrientationIsPortrait(toInterfaceOrientation)){ self.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryOverlay; } else{ //if (self.displayMode == UISplitViewControllerDisplayModePrimaryOverlay) { self.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryHidden; self.preferredDisplayMode = UISplitViewControllerDisplayModeAllVisible; self.preferredDisplayMode = UISplitViewControllerDisplayModeAutomatic; } } } } - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { if (isPad) { if (!UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation])){ self.preferredDisplayMode =UISplitViewControllerDisplayModePrimaryOverlay; } } [self resetSplit:toInterfaceOrientation]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (BOOL)splitViewController:(UISplitViewController *)splitViewController collapseSecondaryViewController:(UIViewController *)secondaryViewController ontoPrimaryViewController:(UIViewController *)primaryViewController { return YES; } 
-one
source share

All Articles