且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

禁用手势以下拉表单/页面表单模式演示

更新时间:2021-12-18 22:14:45

通常,您不应尝试禁用滑动以关闭功能,因为用户希望所有表单/页面在所有应用程序中的行为均相同.相反,您可能需要考虑使用全屏演示样式.如果您确实想要使用无法通过滑动消除的纸张,请设置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.