VoiceOver Z gesture won't trigger when UIAlertController is active

前端 未结 1 1211
迷失自我
迷失自我 2021-01-25 16:56

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 imple

1条回答
  •  醉梦人生
    2021-01-25 17:22

    To get the desired result on your alert view thanks to the scrub gesture, override accessibilityPerformEscape() in the alert view itself.

    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.

    The function findMyViewController has been found here.

    0 讨论(0)
提交回复
热议问题