Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIPageViewController disable scrolling

I am using a UIPageViewController with transitionStyle UIPageViewControllerTransitionStyleScroll and navigationOrientation UIPageViewControllerNavigationOrientationVertical

I also have a UIPanGestureRecognizer on the view and I want to disable page scrolling when the pan gesture is active.

I am trying to set the following when the gesture begins:

pageViewController.view.userInteractionEnabled = NO;

This seems to have no effect, or it appears to work sporadically.

The only other way I have found to do it (which works) is to set the UIPageViewController dataSource to nil while the pan gesture is running, however this causes a huge delay when resetting the dataSource.

like image 844
simon Avatar asked Nov 14 '12 05:11

simon


2 Answers

For those who are using swift instead of objective-c, here is Squikend's solution transposed.

func findScrollView(#enabled : Bool) {
    for view in self.view.subviews {
      if view is UIScrollView {
        let scrollView = view as UIScrollView
        scrollView.scrollEnabled = enabled;
      } else {
        println("UIScrollView does not exist on this View")
      }

    }
  }
like image 167
andrewCanProgram Avatar answered Oct 22 '22 08:10

andrewCanProgram


UIPageViewController uses some UIScrollView object to handle scrolling (at least for transitionStyle UIPageViewControllerTransitionStyleScroll). You can iterate by controller's subviews pageViewController.view.subviews to get it. Now, you can easly enable/disable scrolling:

- (void)setScrollEnabled:(BOOL)enabled forPageViewController:(UIPageViewController*)pageViewController
{
    for (UIView *view in pageViewController.view.subviews) {
        if ([view isKindOfClass:UIScrollView.class]) {
            UIScrollView *scrollView = (UIScrollView *)view;
            [scrollView setScrollEnabled:enabled];
            return;
        }
    }
}
like image 41
squikend Avatar answered Oct 22 '22 07:10

squikend