[英]How do I get vertical swipes in a page view controller
I want a user to normally be able to swipe right to left through the pages of the page view controller, but I also want the user to swipe up on a page to save the content of that page.我希望用户通常能够在页面视图控制器的页面中从右向左滑动,但我也希望用户在页面上向上滑动以保存该页面的内容。 So far I have tried adding a gesture recogniser but it interferes with the page view controller.
到目前为止,我已尝试添加手势识别器,但它会干扰页面视图控制器。 I have tried many thins like adding the gesture recogniser to the window, or a hidden view but it keeps messing with the page view controller.
我尝试了很多方法,比如将手势识别器添加到窗口或隐藏视图,但它一直与页面视图控制器混淆。
All in all is there a way that mainly horizontal swipes get picked up by the page view controller(so they move to the next viewcontroller), but vertical swipes are picked by by me and I can play an animation and trigger a function or something...总而言之,有一种方法主要是水平滑动被页面视图控制器拾取(因此它们移动到下一个视图控制器),但垂直滑动由我拾取,我可以播放动画并触发功能或其他东西。 ..
It looks like UIPageViewController
exposes its gesture recognizers with the property gestureRecognizers
.看起来
UIPageViewController
使用属性gestureRecognizers
公开其手势识别gestureRecognizers
。
You should be able to attach your swipe up gesture recognizer to the page's view.您应该能够将向上滑动手势识别器附加到页面视图。
You'd then tell your gesture recognizer that it should only work when the page view controler's gesture recognizers fail.然后你会告诉你的手势识别器它应该只在页面视图控制器的手势识别器失败时工作。 You'd call your gesture recognizer's
require(toFail:)
method for each of the page view controller's gesture recognizers.您将为每个页面视图控制器的手势识别器调用手势识别器的
require(toFail:)
方法。
(You should read the Xcode documentation on UIGestureRecognizer
. It explains how you can set up dependencies between gesture recognizers so that one has to fail before the next one will evaluate, for situations like this one.) (您应该阅读关于
UIGestureRecognizer
的 Xcode 文档。它解释了如何设置手势识别器之间的依赖关系,以便在下一个评估之前必须失败,对于这种情况。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.