Search code examples
iphoneipaduigesturerecognizeruipageviewcontroller

Can I disable the UIPageViewController's page border gesture recognizers? And keep the swipe one?


I see that I can remove all of the UIPageViewController gestures, but what if I only want to remove the tap gesture on the edges? And keep the swipe gesture? Is this possible?

Thanks


Solution

  • Try looping through pageViewController.gestureRecognizers, disabling any that are tap recognizers.

    Objective-C:

    for (UIGestureRecognizer *recognizer in pageViewController.gestureRecognizers) {
        if ([recognizer isKindOfClass:[UITapGestureRecognizer class]]) {
            recognizer.enabled = NO;
        }
    }
    

    Swift:

    for recognizer in pageViewController.gestureRecognizers {
        if recognizer is UITapGestureRecognizer {
            recognizer.isEnabled = false
        }
    }