TechnologiesSwiftUIAccessibility

AccessibilityDirectTouchOptions struct

iOSmacOStvOSwatchOSvisionOSiOS 17.0+✓ renders

An option set that defines the functionality of a view's direct touch area.

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.

  1. Conform to OptionSet to combine behaviors

    AccessibilityDirectTouchOptions is an OptionSet, 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.

  2. Choose .silentOnTouch to suppress feedback

    The silentOnTouch member 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 the Rectangle drum pad respond cleanly to a tap rather than announcing itself first.

  3. Apply it with accessibilityDirectTouch(_:)

    An AccessibilityDirectTouchOptions value only takes effect when handed to the accessibilityDirectTouch(_:) 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 filled Rectangle, so the touchable area and the option set are declared in one place.

  4. 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 — AccessibilityDirectTouchOptions governs the touch behavior while the label tells the user what this surface is.

Try it — Change [.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.

AccessibilityDirectTouchOptions.swift
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()
    }
}
Live preview
Drum Pad Tap me
Drum Pad Tap me
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →