UISplitViewController swipe gesture prevents another swipe gesture
I am using UISplitViewController
, and one of the detail view controllers contains the view it is added to UIPanGestureRecognizer
. When I scroll through this view in the detail view controller, the gesture is recognized, but the split view manager's gesture recognizer interferes with it; the main view manager is displayed, and the gesture recognizer from the part controller is ignored.
The implementation and debugging of the method shouldRecognizeSimultaneouslyWithGestureRecognizer
from UIGestureRecognizerDelegate
shows two objects UIPanGestureRecognizer
, one from the detailed view controller and one from the split view controller, so I'm pretty sure they are interfering with each other.
When I set presentsWithGesture = NO
on the split view controller, the gesture recognizer inside the detail view controller works. But this disables the gesture recognizer on the split view controller, so this is not a solution to the problem.
I have also tried disabling the gesture recognizer on the split view controller only when I need another gesture recognizer to work, but it seems not possible to set presentsWithGesture
after the split view controller is visible.
I also tried to disable the default gesture on the split view controller and add a custom gesture that I can control, but it doesn't work. I tried to use buttons target
and action
in split view control panel on gesture, but it doesn't work. Calling toggleMasterVisible:
on a split view controller is not an option either because it is part of a private api.
Does anyone have any suggestions on how to handle this?
source to share
I would suggest that you disable the gesture UISplitViewController
when you need another one to work. This should do it:
for (UIGestureRecognizer* recognizer in [splitViewController gestureRecognizers]) {
if ([recognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
[recognizer setEnabled:NO];
}
}
You probably don't want to search for it every time, so I would keep a link to that gesture recognizer when loading a view, and then just disable and enable it as appropriate:
on viewDidLoad:
for (UIGestureRecognizer* recognizer in [splitViewController gestureRecognizers]) {
if ([recognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
[self setSplitViewPanGesture:recognizer];
}
}
later:
[self.splitViewPanGesture setEnabled:NO];
and later:
[self.splitViewPanGesture setEnabled:YES];
source to share