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
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.