如何禁用UIPageViewController的滑动手势

如何禁用UIPageViewController的滑动手势

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

问题描述

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

In my case parent UIViewController contains UIPageViewController which contains UINavigationController which contains UIViewController. I want 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.

以上内容可以从(概述,第二段):

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

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

08-14 02:48