UIPageViewController Traps All UITapGestureRecognizer Events

∥☆過路亽.° 提交于 2019-12-04 08:37:46
Basem Saadawy

Try to iterate through UIPageViewController.GestureRecognizers and assign self as a delegate for those gesture and implement

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch;

Your code may be like this:

In viewDidLoad

for (UIGestureRecognizer * gesRecog in self.pageViewController.gestureRecognizers)
{
        gesRecog.delegate = self;
}

And add the following method:

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    if (touch.view != self.pageViewController.view]
    {
        return NO;
    }
    return YES;
}

The documented way to prevent the UIPageViewController from scrolling is to not assign the dataSource property. If you assign the data source it will move into 'gesture-based' navigation mode which is what you're trying to prevent.

Without a data source you manually provide view controllers when you want to with setViewControllers:direction:animated:completion method and it will move between view controllers on demand.

The above can be deduced from Apple's documentation of UIPageViewController (Overview, second paragraph):

To support gesture-based navigation, you must provide your view controllers using a data source object.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!