UIPageViewController禁用滚动

sim*_*mon 10 uipageviewcontroller ios6

我正在使用带有transitionStyle UIPageViewControllerTransitionStyleScroll和navigationOrientation 的UIPageViewControllerUIPageViewControllerNavigationOrientationVertical

我也有一个UIPanGestureRecognizer视图,我想在平移手势处于活动状态时禁用页面滚动.

我想在手势开始时设置以下内容:

pageViewController.view.userInteractionEnabled = NO;
Run Code Online (Sandbox Code Playgroud)

这似乎没有任何效果,或者似乎偶尔起作用.

我发现做它的唯一另一种方法(工作)是在平移手势运行时将UIPageViewController dataSource设置为nil,但这会在重置dataSource时造成巨大延迟.

小智 23

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;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)