Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Registering UIGestureRecognizer actions in voice over

I have a standard UIViewController and register a UISwipeGestureRecognizer, delegate the view to it in my viewDidLoad override.

The gesture registers and call the appropriate action correctly, however this does not happen when voice over is on.

Is UIGestureRecognizer only available for standard usage in iOS? Is there a way to get voice over to register these gestures, whether double taps, swipes, pinch/zoom etc?

like image 503
triple7 Avatar asked Feb 15 '17 03:02

triple7


1 Answers

Figured out how this works, and I think it's worth sharing this:

After looking around at UIView classes, as well as UIAccessibilityTraits, all UIViews and their subclasses have a bitmask using various UIAccessibilityTraits which can be used to: -Designate the standard behavior of the UIView or any class adopting the UIAccessibility protocol. -Allow various configurations such as refresh speed, enabling slider type behavior etc.

Here is a link to all the available traits: https://developer.apple.com/reference/uikit/uiaccessibility/accessibility_traits

For my specific case, I used UIAccessibilityTraitAllowsDirectInteraction and UIAccessibilityTraitUpdatesFrequently. All UIGestureRecognizers then are properly registered, whether swipe, taps, pinch, etc.

They need to be specified as a bitmask, so if you need an element to have these properties, type in:

myView.UIAccessibilityTraits = UIAccessibilityTraitAllowsDirectInteraction | UIAccessibilityTraitUpdatesFrequently

Compiled, ran the app and I got the view telling me what it is, and swiping registers properly without that "bonk" sound you get when something is wrong.

Hope this helps those who also wondered how to get it to work, however this might also conflict slightly with custom views depending on how you want either sighted or visually impaired users to experience the UI. However, I find this way more elegant than creating a whole set of UIElements just to accomodate voice over usage as the interactive method stays the same, and there's no need to write code to hint or explain what to do.

like image 150
triple7 Avatar answered Nov 15 '22 04:11

triple7