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

问题描述

在我的例子中,父 UIViewController 包含 UIPageViewController,其中包含 UINavigationController,其中包含 UIViewController.我需要向最后一个视图控制器添加一个滑动手势,但是滑动的处理就像它们属于页面视图控制器一样.我尝试以编程方式和通过 xib 执行此操作,但没有结果.

In my case parent UIViewController contains UIPageViewController which contains UINavigationController which contains UIViewController. I need to add a swipe gesture to the last view controller, but swipes are handled as if they belong to page view controller. I tried to do this both programmatically and via xib but with no result.

据我所知,在 UIPageViewController 处理其手势之前,我无法实现我的目标.如何解决这个问题?

So as I understand I can't achieve my goal until UIPageViewController handles its gestures. How to solve this issue?

推荐答案

已记录的防止 UIPageViewController 滚动的方法是不分配 dataSource 属性.如果您分配数据源,它将进入基于手势"的导航模式,这正是您要阻止的.

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.

如果没有数据源,当您想使用 setViewControllers:direction:animated:completion 方法时手动提供视图控制器,它将根据需要在视图控制器之间移动.

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.

以上可以从 Apple 的 UIPageViewController 文档推导出(概述,第二段):

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

要支持基于手势的导航,您必须使用数据源对象提供视图控制器.

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

08-14 02:48