Hiding A SwiftUI View From Switch Control
I'm currently working on a project to enhance the accessibility of an app, and I'm learning a lot about how far iOS's accessibility support goes beyond a screen reader. There's a really cool technology called Switch Control that enables users to control their iPhones using an external tool, like a button, a game controller, or even a straw.
I ran into a problem with supporting Switch Control when I was building a custom View component in SwiftUI. The component is essentially a label, and shouldn't be visible to Switch Control. But it wasn't easy to find out how to hide it. Switch Control is such a vague term that I got a lot of results for custom control components called switches, and some results about using a Nintendo Switch controller too.
The solution to my problem was quite easy, once I found it. A one-line SwiftUI modifier:
.accessibilityRespondsToUserInteraction(false)
Here is the relevant part of the docs from Apple:
Explicitly set whether this Accessibility element responds to user interaction and would thus be interacted with by technologies such as Switch Control, Voice Control or Full Keyboard Access.
Find out more about Switch Control
Switch Control is a really cool technology, but not widely known or talked about. Here are some interesting articles from people using it, if you want to find out more:
Published on 4 September 2024