Hiding Elements

suggest change

Most UIKit classes, including UIView, adhere to UIAccessibilityProtocol and return correct values by default. It’s easy to take for granted that a UIView set to hidden is also absent from the accessibility hierarchy and won’t be navigated by VoiceOver. While this default behavior is usually sufficient, there are times where a view will be present in the view hierarchy but not visible or navigable. For example, a collection of buttons may be overlapped by another view, rendering them invisible to a sighted user. VoiceOver, however, will still try to navigate them since they are technically not hidden from UIKit and therefore are still present in the accessibility hierarchy. In such cases, you must hint to VoiceOver that the parent view isn’t accessible. You can do this by explicitly hiding the view from UIKit by setting hidden when the view goes offscreen:

myViewFullofButtons.hidden = YES;

Alternatively, you can leave the parent view visible and simply hide its children from the accessibility hierarchy:

myViewFullofButtons.accessibilityElementsHidden = YES;

Temporary views are a another place you’ll want to hide elements from the accessibility hierarchy while leaving them visible to users. For example, the view that pops up when you hit the volume button is visible to sighted users but doesn’t demand attention the way a normal alert does. You wouldn’t want VoiceOver to interrupt the user and move the cursor from away from whatever they were doing to announce the new volume, especially given that adjusting volume already provides auditory feedback through the clicking sound it makes. In cases like this, you’ll want to hide the view using accessibilityElementsHidden.

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents