I am trying to disable the pan gesture recognizer for a UIPageViewController.
On iOS 5 I can loop through them and disable them.
for (UIGestureRecognizer* recognizer in self.pageViewController.gestureRecognizers) {
if ([recognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
recognizer.enabled = NO;
}
}
On iOS 6 using UIPageViewControllerTransitionStyleScroll there are no gesture recognizers returned by the Page View Controller.
Clarification
This can be boiled down to:
self.pageViewController.gestureRecognizers = 0 when UIPageViewController’s transition style is set to scroll so I can’t access the gesture recognizers.
Is there any way I can get around this? I don’t think I am doing anything wrong since the curl transition works fine.
There is a bug filed in radar for this behavior. So, I bet that until Apple fixes it there will be no chance to solve this.
One workaround that comes to my mind is laying a transparent subview on top of your
UIPageViewControllerand add to it aUIPanGestureRecognizerto intercept that kind of gesture and not forward further. You could enable this view/recognizer when disabling the gesture is required.I tried it with a combination of Pan and Tap gesture recognizers and it works.
This is my test code:
When
g2is enabled, it will preventg1from being recognized. On the other hand, it will not prevent s1 from being recognized.I understand this is hack, but in the face of a seeming bug in
UIPageViewController(at least, actual behavior is blatantly different from what the reference states), I cannot see any better solution.