UIPageViewController禁用滚动(UIPageViewController disa

2019-07-03 19:26发布

我使用同一个transitionStyle UIPageViewController UIPageViewControllerTransitionStyleScroll和navigationOrientation UIPageViewControllerNavigationOrientationVertical

我也有一个UIPanGestureRecognizer的看法,我想禁用页面滚动时的移动手势被激活。

我想手势开始时设置如下:

pageViewController.view.userInteractionEnabled = NO;

这似乎没有任何效果,或出现零星工作。

我发现这样做的唯一的其他方式(工作)是设置UIPageViewController的数据源无锅姿态运行时,然而,这重置数据源时会导致巨大的延迟。

Answer 1:

UIPageViewController使用一些UIScrollView的对象来处理滚动(至少对于transitionStyle UIPageViewControllerTransitionStyleScroll )。 你可以通过控制器的子视图迭代pageViewController.view.subviews得到它。 现在,您可以伊斯利启用/禁用滚动:

- (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;
        }
    }
}


Answer 2:

对于那些谁使用,而不是迅速的Objective-C,这里是Squikend的解决方案换位。

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")
      }

    }
  }


Answer 3:

这个怎么样?

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


Answer 4:

答案的雨燕4.2版本

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

    }
}

然后yourpagecontorller.findScrollView(启用:假)



文章来源: UIPageViewController disable scrolling