通过外部点击 + VoiceOver 模式关闭 iOS 表单 sheet 模式

Dismiss iOS form sheet modal via outside tap + VoiceOver mode

在 iPad 上,您可以使用 controller.modalPresentationStyle = UIModalPresentationFormSheet 在屏幕上显示居中模式。一种常见的技术是允许用户通过单击 "outside" 或 "behind" 来关闭模态。许多其他答案都涵盖了这一点(Iphone SDK dismissing Modal ViewControllers on ipad by clicking outside of itDismiss modal view form sheet controller on outside tap),通常是通过向视图的 UIWindow 添加点击手势。

我的问题是,如何让处于 VoiceOver 模式的用户可以访问它?本机操作 sheets 允许在 sheet 之外的点击关闭,甚至提示用户说 "double tap to dismiss popup window"。如何以相同的方式公开 UIWindow 点击手势?

FormSheet 演示文稿基本上无法做到这一点。您可以使用 Popover 表示,但在某些情况下它的行为会有所不同。

我的解决方案是检查 UIAccessibilityIsVoiceOverRunning() 并在 FormSheet 的顶部添加一个额外的关闭按钮元素,可以通过画外音单击。我还为 global escape gesture.

实现了 accessibilityPerformEscape

来自苹果:

https://support.apple.com/guide/iphone/learn-voiceover-gestures-iph3e2e2281/ios

Dismiss an alert or return to the previous screen: Two-finger scrub (move two fingers back and forth three times quickly, making a “z”).

如果模式 sheet 打开,我们可以提示用户 "make a z gesture" 返回。