How to suppress the gestures of a Master-Detail Controller hard drive and recreate its behavior on iOS 7

By default, the UISplitViewController provides swipe gestures to open the main view in portrait mode.

Unfortunately, this gesture opens the master controller even when manipulating the sliders on the details page! I found another question here, where it was noted as a bug reported for iOS 5.1, and yet the problem persists on iOS7 ...

Is there a way to suppress this gesture in these circumstances? I understand that I can completely remove it by doing the following:

splitViewController.presentsWithGesture = NO; 

However, it would be nice to allow the gesture and still use the sliders!

+7
objective-c ios7 uisplitviewcontroller
source share
1 answer

After experimenting, I wondered what would happen if I tried to create my own gesture of gestures to open the main view. This works great, and it won't work when using the sliders!

So, in application deletion, I suppress the default gesture:

 splitViewController.presentsWithGesture = NO; 

When the detail view loads, I create a gesture of gestures:

 - (void)viewDidLoad { [super viewDidLoad]; UISwipeGestureRecognizer *swipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleRightSwipe:)]; swipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionRight; [self.view addGestureRecognizer:swipeGestureRecognizer]; [self configureView]; } 

In splitViewController: willHideViewController: withBarButtonItem: forPopoverController: I keep the links that I need to open the main view:

 - (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)popoverController { // Add the bar item to the navigation bar barButtonItem.title = NSLocalizedString(@"Master", @"Master"); [self.navigationItem setLeftBarButtonItem:barButtonItem animated:YES]; // Store references to the button and popover controller so that we can manually open the view using a custome swipe gesture self.masterPopoverButton = barButtonItem; self.masterPopoverController = popoverController; } 

Finally, I process the napkins:

 - (void)handleRightSwipe:(UISwipeGestureRecognizer *)recognizer { // Find the root controller in the stack (this is the one that also the split view delegate, and thus has access // to the pop over controller. MyDetailViewController *rootController = (MyDetailViewController *)[self.navigationController.viewControllers objectAtIndex:0]; if (!rootController.masterPopoverController.popoverVisible) { [rootController.masterPopoverController presentPopoverFromBarButtonItem:rootController.masterPopoverButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; } } 

Slide in the main controller. I was worried that this would display the controller as a traditional popover (with arrows, etc.), but actually it does the right thing (at least in iOS 7 - I have not tested earlier versions).

Note that you need to create this gesture for each view that you click on the navigation controller stack. In my case, it is always the same view, which simplifies things. In other cases, it might be a good idea to subclass a UIViewController that creates this gesture and processes it, and then use it as a superclass for any controllers that are clicked ...

+6
source share

All Articles