UIPageViewController禁用滚动 [英] UIPageViewController disable scrolling

查看:842
本文介绍了UIPageViewController禁用滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using a UIPageViewController with transitionStyle UIPageViewControllerTransitionStyleScroll and navigationOrientation UIPageViewControllerNavigationOrientationVertical

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

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.

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

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.

推荐答案

UIPageViewController使用一些UIScrollView对象来处理滚动(至少对于transitionStyle UIPageViewControllerTransitionStyleScroll )。您可以按控制器的子视图 pageViewController.view.subviews 进行迭代以获取它。现在,您可以轻松启用/禁用滚动:

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

这篇关于UIPageViewController禁用滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆