What is the difference between isAccessibilityElement and accessibilityElementsHidden? The first one makes the view not accessible, but its subviews can still be accessible. The second one hides the view and all its subviews from assistive tech.

There is a view containing 4 subviews. Three examples. In the three of them, all the subviews (that we'll refer to as 1, 2, 3 and 4) have the isAccessibilityElement property set to true. In the first example, the superview (that we'll refer to as A) also has the isAccessibilityElement property to true. That means that A is accessible, but 1, 2, 3 and 4 aren't. In the second example A has the isAccessibilityElement property set to false. That means that A isn't accessible, but 1, 2, 3 and 4 are accessible. In the third example, A has isAccessibilityElement to false and accessibilityElementsHidden to true. That means that A, 1, 2, 3 and 4 will not be accessible.

You may also find interesting...

When setting isAccessibilityElement to true, assistive tech like VoiceOver will stop looking for other accessible elements in that view hierarchy. So if we make a view accessible, its subviews, including buttons and labels won't be accessible.

It is possible to change the traversing order of accessibility elements by configuring the accessibilityElements array. You should try to avoid it, but one good reason for doing it is if the default order is illogical because of the visual layout.

If you need for a view (and all its subviews) not to be focusable by assistive tech like VoiceOver, you can set its accessibilityElementsHidden property to true. This isn't needed very often, but it can be useful for certain custom experiences.

Created in Swift with Ignite.

Supporting Swift for Swifts