我正在尝试使用Z手势关闭UIAlertController.我有一个非常简单的应用程序.它具有1个按钮的单个视图.轻击按钮会发出警报.我已经实现了
I'm trying to use the Z gesture to dismiss a UIAlertController. I have a very simple app. It has a single view with 1 button. Tapping the button presents an alert. I have implemented
- (BOOL)accessibilityPerformEscape { NSLog(@"Z gesture"); return YES; }在启用VoiceOver的情况下,擦洗屏幕会打印出"Z手势",但是当我按下按钮并且看到警报时,擦洗屏幕不会执行任何操作,不会调用该方法,也不会打印任何内容.我该怎么办才能使警报在屏幕上显示出来?
With VoiceOver on, scrubbing the screen prints out "Z gesture," but when I press the button and the alert is visible, scrubbing the screen does nothing, the method is not called and nothing is printed. What do I have to do to get this to function while the alert is on screen?
谢谢...
推荐答案由于要进行擦洗手势,因此要在警报视图中获得所需的结果,请在警报视图本身中覆盖accessibilityPerformEscape().
To get the desired result on your alert view thanks to the scrub gesture, override accessibilityPerformEscape() in the alert view itself.
解决方案可能是在UIView扩展中实现此替代,如下所示:
A solution could be to implement this override in an UIView extension as follows :
extension UIView { override open func accessibilityPerformEscape() -> Bool { if let myViewController = self.findMyViewController() as? UIAlertController { myViewController.dismiss(animated: true, completion: nil) } return true } private func findMyViewController() -> UIViewController? { if let nextResponder = self.next as? UIViewController { return nextResponder } else if let nextResponder = self.next as? UIView { return nextResponder.findMyViewController() } else { return nil } } }该代码足够简短,无需进一步说明即可理解.如果不清楚,请不要犹豫.
The code is short enough to be understood without further explanation. If it's not clear, don't hesitate to ask.
已找到功能findMyViewController 此处.
更多推荐
UIAlertController处于活动状态时,不会触发VoiceOver Z手势
发布评论