When VoiceOver is active on an iOS device, the single-finger swipe(left or right) gesture allows users to browse the different elements in the view. Is there a way to detect if
You might be asking either of 2 things:
You want to know when the VoiceOver user successfully issued the single-finger swipe left/right gesture to VoiceOver - VoiceOver will process ("steal") the gesture from your code and do its thing (move VoiceOver cursor to the next/previous element). The closest you can get is to get notifications for a UIView when the VoiceOver cursor lands on it or leaves it (see the UIAccessibilityFocus protocol).
You want to make part of your UI not subject to VoiceOver gestures (VoiceOver will not process ("steal") gestures in this area) so that you can detect the gestures yourself (including the single-finger swipe left/right) in a standard way and process them in the way you want for your app. Then you must add the UIAccessibilityTraitAllowsDirectInteraction
trait to the accessibilityTraits
property to the relevant UIView
(see UIAccessibility protocol for more details). A prominent example of where this is used is in GarageBand for iOS - the piano keyboard or drums have this trait so that VoiceOver user can play on the instruments without turning VoiceOver off.
I ended up creating a category/extension on UIView and overriding accessibilityElementDidBecomeFocused().
Here I can get a global hook, which gets called every time the accessibility state has changed.
Swift example:
extension UIView {
//MARK: Accessibility
override public func accessibilityElementDidBecomeFocused() {
super.accessibilityElementDidBecomeFocused()
UIApplication.sharedApplication().sendEvent(UIEvent())
}
}