How it works
AccessibilityDirectTouchOptions is an option set that tunes how a view behaves when it participates in direct-touch accessibility interactions. Normally VoiceOver intercepts touches so users can explore the screen by feel before activating anything, but some controls — instruments, drawing surfaces, signature fields — need to receive raw touches the moment a finger lands. You opt a view into that direct-touch behavior with the accessibilityDirectTouch(_:) modifier, and you pass an AccessibilityDirectTouchOptions value to refine exactly how those passthrough touches are handled. Reach for it when a view's whole purpose is the touch itself, not the element behind it.
Conform to OptionSet to combine behaviors
AccessibilityDirectTouchOptionsis anOptionSet, so its values are flags you can union together. You express even a single choice as an array literal — in the example the options are written as[.silentOnTouch], and you would add more members inside the same brackets to compose several behaviors at once.Choose .silentOnTouch to suppress feedback
The
silentOnTouchmember tells the system to pass touches through to the view without VoiceOver speaking or playing its usual interaction feedback. That keeps an audio- or gesture-driven control from competing with assistive output — here it lets theRectangledrum pad respond cleanly to a tap rather than announcing itself first.Apply it with accessibilityDirectTouch(_:)
An
AccessibilityDirectTouchOptionsvalue only takes effect when handed to theaccessibilityDirectTouch(_:)view modifier, which marks the view as a direct-touch region and forwards your options to it. In the example.accessibilityDirectTouch([.silentOnTouch])is attached to the filledRectangle, so the touchable area and the option set are declared in one place.Keep a label so the region stays identifiable
Direct-touch passthrough changes how touches activate the view, not whether it is described, so you still give it meaning for accessibility navigation. The adjacent
.accessibilityLabel("Drum pad, plays on touch")names the region —AccessibilityDirectTouchOptionsgoverns the touch behavior while the label tells the user what this surface is.
[.silentOnTouch] to [] and observe how the drum pad reverts to standard VoiceOver activation feedback instead of responding silently to direct touch.Example & preview
Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.
struct AccessibilityDirectTouchOptionsDemo: View {
var body: some View {
VStack(spacing: 12) {
Text("Drum Pad")
.font(.headline)
Rectangle()
.fill(.blue.gradient)
.frame(width: 160, height: 80)
.overlay(Text("Tap me").foregroundStyle(.white))
.accessibilityDirectTouch([.silentOnTouch])
.accessibilityLabel("Drum pad, plays on touch")
}
.padding()
}
}