禁用手势以下拉表单/页面表单模式演示 [英] Disable gesture to pull down form/page sheet modal presentation

查看:104
本文介绍了禁用手势以下拉表单/页面表单模式演示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS 13中,可以使用平移手势关闭使用表单和页面工作表样式的模式演示.在我的一张表单中,这是有问题的,因为用户会拖入该框,而这会干扰手势.它将屏幕向下拉,而不是绘制垂直线.

In iOS 13 modal presentations using the form and page sheet style can be dismissed with a pan down gesture. This is problematic in one of my form sheets because the user draws into this box which interferes with the gesture. It pulls the screen down instead of drawing a vertical line.

如何在以表格形式显示的模态视图控制器中禁用垂直滑动以消除手势?

How can you disable the vertical swipe to dismiss gesture in a modal view controller presented as a sheet?

设置isModalInPresentation = true仍然可以将工作表拉下,只是不会消失.

Setting isModalInPresentation = true still allows the sheet to be pulled down, it just won't dismiss.

推荐答案

通常,您不应尝试禁用滑动以关闭功能,因为用户希望所有表单/页面在所有应用程序中的行为均相同.相反,您可能需要考虑使用全屏演示样式.如果您确实想要使用无法通过滑动消除的纸张,请设置isModalInPresentation = true,但请注意,这仍然允许垂直下拉纸张,并且在松开触摸时会弹起.请查看 UIAdaptivePresentationControllerDelegate 文档,以在用户尝试通过滑动将其关闭时做出反应.动作.

In general, you shouldn't try to disable the swipe to dismiss functionality, as users expect all form/page sheets to behave the same across all apps. Instead, you may want to consider using a full-screen presentation style. If you do want to use a sheet that can't be dismissed via swipe, set isModalInPresentation = true, but note this still allows the sheet to be pulled down vertically and it'll bounce back up upon releasing the touch. Check out the UIAdaptivePresentationControllerDelegate documentation to react when the user tries to dismiss it via swipe, among other actions.

如果您的应用程序的手势或触摸处理受到取消滑动功能的影响,那么我确实从Apple工程师那里收到了一些有关如何解决该问题的建议.

If you have a scenario where your app's gesture or touch handling is impacted by the swipe to dismiss feature, I did receive some advice from an Apple engineer on how to fix that.

如果可以阻止系统的平移手势识别器启动,则可以防止手势解雇.几种方法可以做到这一点:

If you can prevent the system's pan gesture recognizer from beginning, this will prevent the gestural dismissal. A few ways to do this:

  1. 如果您的画布绘制是使用手势识别器(例如您自己的UIGestureRecognizer子类)完成的,请在工作表的关闭手势之前输入began阶段.如果您以UIPanGestureRecognizer的速度识别,您将获胜,并且工作表的关闭手势将被颠覆.

  1. If your canvas drawing is done with a gesture recognizer, such as your own UIGestureRecognizer subclass, enter the began phase before the sheet’s dismiss gesture does. If you recognize as quickly as UIPanGestureRecognizer, you will win, and the sheet’s dismiss gesture will be subverted.

如果使用手势识别器完成了画布绘制,请使用-shouldBeRequiredToFailByGestureRecognizer:(或相关的委托方法)设置动态失败要求,如果传入的手势识别器是NO >.

If your canvas drawing is done with a gesture recognizer, setup a dynamic failure requirement with -shouldBeRequiredToFailByGestureRecognizer: (or the related delegate method), where you return NO if the passed in gesture recognizer is a UIPanGestureRecognizer.

如果您的画布绘制是通过手动触摸处理完成的(例如touchesBegan:),请在触摸处理视图上覆盖-gestureRecognizerShouldBegin,如果传入的手势识别器为UIPanGestureRecognizer,则返回NO.

If your canvas drawing is done with manual touch handling (e.g. touchesBegan:), override -gestureRecognizerShouldBegin on your touch handling view, and return NO if the passed in gesture recognizer is a UIPanGestureRecognizer.

在我的设置3中,事实证明效果很好.这样一来,用户就可以向下滑动绘图画布之外的任何位置以关闭它(例如导航栏),同时允许用户在不移动图纸的情况下进行绘图,就像人们期望的那样.

With my setup #3 proved to work very well. This allows the user to swipe down anywhere outside of the drawing canvas to dismiss (like the nav bar), while allowing the user to draw without moving the sheet, just as one would expect.

我不建议尝试找到禁用该手势的手势,因为它似乎是动态的,并且例如在不同大小的类之间切换时可以重新启用自身,并且在将来的版本中可能会更改.

I cannot recommend trying to find the gesture to disable it, as it seems to be rather dynamic and can reenable itself when switching between different size classes for example, and this could change in future releases.

这篇关于禁用手势以下拉表单/页面表单模式演示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆