Configuring Voice Over to ignore sibling views when an overlapping view is added in Swift

Pavan Kataria
2 min readMay 29, 2020

I came across a bug where Voice Over was not announcing elements in the way we wanted. I had an overlapping view which could be presented dynamically and when presented we wanted the sibling views’ elements not to be announced.

This is what the hierarchy looked like:

ComponentContainerView subviews [
ViewA,
RefreshView // This view is added and removed.
]

The RefreshView is a dynamic view that overlaps ViewA completely when presented. Here is an example on how a view can be added modally and removed:

By default Voice Over will traverse through the hierarchy and announce the view elements, First it will go through the elements in ViewA and then through the elements in RefreshView.

Since the RefreshView can overlap ViewA modally we want to ensure accessibility elements in the underlying ViewA are not announced when the overlapping RefreshView is presented modally. Voice Over doesn’t know when sibling views are overlapping so we need to configure Voice Over to let it know which view is the modal view so it can ignore the elements in the sibling views.

accessibilityViewIsModal to the rescue

Apple introduced the accessibilityViewIsModal property in iOS 5 and recently in Mac Catalyst 13.0. The default value is false but when set to true Voice Over will ignore sibling views with the same parent. So in our case, setting accessibilityViewIsModal to true on RefreshView causes Voice Over to ignore elements in ViewA because they share the exact same parent.

As well as setting this property to true you also need to post a .screenChanged notification to UIAccessibility of course to let Voice Over know the accessibilityElements on the screen have changed.

This is all you need to do to ensure the Voice Over will ignore ViewA without having to have tracking code to manage your accessibility elements. This is what we ended up doing and it got rid of the bugs we were seeing.

I’m happy the bug was resolved and hope you’ve learned something new.

We should all be placing importance and consideration in ensuring all UI features developed are accessible to our accessibility users.

Feel free to share this post and if you enjoyed reading it I’d appreciate you letting me know. You can also check out my Github open source packages.

Thank you

--

--

Pavan Kataria

Engineer Pavan, First of His name, the Unburnt, Lord of the iOS Realm, Bug Breaker, Space Indenter, and New writer — otherwise known as PK