accessibilityZoomAction

Adds an accessibility zoom action to the view. Actions allow assistive technologies, such as VoiceOver, to interact with the view by invoking the action.

View ModifieriOS 16.0+macOS 13.0+tvOS 16.0+watchOS 9.0+accessibilityZoomAction(_:) in SwiftUI

Declaration

React
compose().accessibilityZoomAction(
  handler: (arg0: SwiftUI.AccessibilityZoomGestureAction) => void
)
Swift
nonisolated func accessibilityZoomAction(
    _ handler: @escaping (AccessibilityZoomGestureAction) -> Void
) -> ModifiedContent<Self, AccessibilityAttachmentModifier>

Parameters

Discussion

For example, this is how a zoom action is used to transform the scale of a shape which has a MagnificationGesture.

var body: some View {
    Circle()
        .scaleEffect(magnifyBy)
        .gesture(magnification)
        .accessibilityLabel("Circle Magnifier")
        .accessibilityZoomAction { action in
            switch action.direction {
            case .zoomIn:
                magnifyBy += 0.5
            case .zoomOut:
                 magnifyBy -= 0.5
            }
        }
}

See also

More in Accessibility.