ios - UIPageViewController 不允许识别 UIScreenEdgePanGe

我的应用程序有这个问题。正如您在下面的 Storyboard 屏幕上看到的那样,根 VC (ContainerViewController) 有一个 UIScrollView,并且在这个 ScrollView 中有两个容器。在左侧容器中嵌入了 MenuViewController,在右侧容器中嵌入了 WelcomeViewControllerWelcomeViewController 里面有一个 UIPageViewController

想法是在 UIPageViewController 内部有一个左侧的滑出菜单(使用 scrollView)和右侧的多个 VC。我已经实现了 UIScreenEdgePanGestureRecognizer 以从左边缘显示菜单。它使用以下代码与 scrollView 一起正常工作:

edgePanRecognizer = UIScreenEdgePanGestureRecognizer(target: self, action: #selector(leftScreenEdgeSwiped))
scrollView.panGestureRecognizer.requireGestureRecognizerToFail(edgePanRecognizer)

但是在 UIPageViewController 所在的区域,无法识别 UIScreenEdgePanGestureRecognizer,我只能在页面之间滑动,而不是滑出菜单。 我试过

func gestureRecognizer(UIGestureRecognizer,shouldRecognizeSimultaneouslyWithGestureRecognizer:UIGestureRecognizer) -> Bool {
         return true
} 

但它不起作用。

我将不胜感激如何帮助 UIScreenEdgePanGestureRecognizer 优先于 UIPageViewController 手势。

最佳答案

为了使 UIScreenEdgePanGestureRecognizerUIPageViewController 一起工作,您必须将手势识别器添加到页面 View Controller 实例的 view 属性中.

例子:

let edgePanRecognizer = UIScreenEdgePanGestureRecognizer(target: self, action: #selector(edgeAction(_:)))
edgePanRecognizer.edges = .left        
pageViewController.view.addGestureRecognizer(edgePanRecognizer)

除此之外,添加这行代码是必不可少的:

(pageViewController.view.subviews.filter { $0 is UIScrollView }.first as? UIScrollView)?.panGestureRecognizer.require(toFail: edgePanRecognizer)

关于ios - UIPageViewController 不允许识别 UIScreenEdgePanGestureRecognizer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37296247/

相关文章:

clojure - 为什么我们在 Clojure 中需要所有 3 个 - tesser、transd

android - 如何杀死 fragment ?

amazon-web-services - AWS API Gateway 默认响应和触发器 AWS

msbuild - 在自定义目标中计算的编译器附加选项

angularjs - angularjs处理异常的方法

spring - Spring 中的 RequestMapping 包

c# - 标准化相对路径?

javascript - 使用在 Safari 中不起作用的 javascript 禁用键盘快捷键?

python - NoReverseMatch 在/accounts/signup/django-a

c# - WCF:没有 channel 主动监听