How it works
AccessibilityAdjustmentDirection is the enumeration SwiftUI hands you to describe how an assistive technology user is asking to change an adjustable element's value. When VoiceOver focuses a control marked as adjustable, the user swipes up or down (or uses the rotor) to nudge its value, and the system reports each gesture to your code as one of this enum's directions. Reach for it whenever a view exposes a continuous or stepped value—a rating, a counter, a custom slider—that assistive users need to raise or lower without touching its visual controls.
Read the direction passed to accessibilityAdjustableAction(_:)
An adjustable element advertises itself with the
accessibilityAdjustableActionmodifier, whose closure receives a singleAccessibilityAdjustmentDirectionvalue each time the user performs an adjust gesture. In the example the closure parameterdirectioncarries that value, so your handler runs once per swipe and decides how to mutate the underlying state—here the@Statepropertyrating.Branch on .increment and .decrement
The enum's two primary cases tell you which way the user swiped:
.incrementfor an upward (increase) gesture and.decrementfor a downward (decrease) one. The example switches ondirectionand maps.incrementtorating += 1and.decrementtorating -= 1, clamping each to the 0...5 range so the value never escapes its bounds.Handle future directions with @unknown default
Because AccessibilityAdjustmentDirection is a non-frozen enum, SwiftUI may introduce additional directions in later releases, so an exhaustive switch must include an
@unknown defaultarm. The example's@unknown default: breakkeeps the code forward-compatible—unrecognized directions are simply ignored rather than causing a compile error or crash.Pair adjustments with an accessibilityValue
The direction only describes the change; you are responsible for announcing the result. The view combines
accessibilityValue("\(rating) out of 5")with the adjustable action so that, after each.incrementor.decrement, VoiceOver speaks the new value. TheaccessibilityElement()andaccessibilityLabel("Rating")modifiers establish the single focusable element that the gesture targets.
case .increment: rating += 2 change—or swap the bodies of the .increment and .decrement arms—and listen with VoiceOver to hear how each swipe direction now moves rating differently.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 AccessibilityAdjustmentDirectionDemo: View {
@State private var rating = 3
var body: some View {
VStack(spacing: 12) {
Text("Rating: \(rating)")
.font(.title2)
Text("Swipe up/down with VoiceOver to adjust")
.font(.caption)
.foregroundStyle(.secondary)
}
.accessibilityElement()
.accessibilityLabel("Rating")
.accessibilityValue("\(rating) out of 5")
.accessibilityAdjustableAction { direction in
switch direction {
case .increment:
if rating < 5 { rating += 1 }
case .decrement:
if rating > 0 { rating -= 1 }
@unknown default:
break
}
}
.padding()
}
}