简体   繁体   English

如何在页面视图控制器中获得垂直滑动

[英]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.

相关问题 如何指示用户向哪个方向滑动,而不是Swift中的下一个和上一个视图控制器? - How do I indicate which direction the user swipes, rather the next and previous view controller in Swift? 当滚动视图不在最左侧时,如何防止UINavigationController识别滑动? - How do I prevent a UINavigationController from recognising swipes when my scroll view isn't at the far left? 如何获取显示的视图控制器的顶视图 - How do I get the top view which is a presented view controller 如何为Page View Controller提供“垂直覆盖”过渡样式 - how to give Page View Controller a “Cover Vertical” transition style 我如何获得当前的活动视图控制器? - How do i get current active view controller? 如何获取触发segue的视图控制器 - How do I get the view controller that trigger the segue 如何从另一个视图控制器中的变量获取值 - How do I get a value from a variable in another View Controller iOS-用户滑动屏幕时如何执行操作? - iOS - How do I perform an action when the user swipes the screen? iOS - 拆分视图控制器 - 如何从主视图控制器内部获取指向详细视图控制器的指针(引用)? - iOS - Split View Controller - How do I get a pointer (reference) to the Detail View Controller from inside the Master View Controller? 如何在页面视图控制器中获取当前视图控制器 - How to get current view controller in page view controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM