Shinonuma Shinonuma - 5 months ago 203
Objective-C Question

Disable/enable scrolling in UIPageViewController

I got a

viewController
which inherits from
UIPageViewController
(
@interface PageScrollViewController : UIPageViewController
) Now I'm wondering how I can enable and disable the scrolling from the
UIPageViewController
? When using a
UIScrollView
you would do
setScrollEnabled:NO
and
self.view.userInteractionEnabled = NO;
isn't an option since this blocks the whole
UIView
instead of just the scrolling.

EDIT
This is in the
PageScrollViewController : UIPageViewController
class:

if ([[notification name] isEqualToString:@"NotificationDisable"]){
NSLog (@"Successfully received the disable notification!");
for (UIGestureRecognizer *recognizer in self.gestureRecognizers) {
recognizer.enabled = NO;
}
}

Answer

Try looping through the gestureRecognizers of the UIPageViewController and disable/enable them:

for (UIGestureRecognizer *recognizer in pageViewController.gestureRecognizers) {        
        recognizer.enabled = NO;
}

Note: as found in this SO post, this method will only work for UIPageViewControllerTransitionStylePageCurl. You may want to try this solution (although it seems to be a bit hacky).

Comments