Skip to content

SwiftUI Gestures ​

Implementing SwiftUI gestures that combine correctly, reset when they should, and stay usable with VoiceOver, a keyboard, or a pointer.

When to Use ​

Use this skill when you're:

  • Implementing tap, drag, long press, magnify, or rotate gestures
  • Combining gestures so they run together, in sequence, or exclusively
  • Managing temporary gesture state with GestureState
  • Building a custom gesture
  • Debugging gestures that conflict with each other, a scroll view, or navigation
  • Making a gesture accessible to VoiceOver
  • Handling touch, trackpad, Pencil, and pointer input across iOS, macOS, and visionOS
  • Reacting to pointer hover on iPad, Mac, or iPhone Mirroring

Example Prompts ​

Questions you can ask your assistant that will draw from this skill:

  • "My drag gesture isn't working. The view doesn't move when I drag it."
  • "I have a tap and a drag on the same view, and only the tap works. How do I fix this?"
  • "How do I make people long press before they can drag an item?"
  • "My view stays in the wrong position after the gesture ends."
  • "My drag gesture stops the scroll view from scrolling."
  • "How do I make this custom slider work with VoiceOver?"
  • "How do I let one finger draw while the trackpad scrolls?"
  • "How do I highlight a row when the pointer hovers over it?"

What This Skill Provides ​

Choosing and Building ​

  • A decision tree from the interaction to the gesture, starting with Button for a simple tap
  • Patterns for TapGesture, DragGesture, LongPressGesture, MagnifyGesture, and RotateGesture
  • Custom gestures, velocity, and predicted end location

Composition and State ​

  • simultaneously, sequenced, and exclusively, and when each applies
  • GestureState, which resets by itself, compared with State for committed values
  • Handling a gesture the system cancels

Accessibility and Keyboards ​

  • Accessibility actions and adjustable actions for custom gestures
  • Keyboard alternatives on the Mac, and default and cancel shortcuts

Platforms and Pointers ​

  • How each gesture maps to iOS, macOS, and visionOS
  • Filtering by input kind on the 27 releases, for touch-display Macs and Sidecar
  • onHover, onContinuousHover, hoverEffect, and pointerStyle (macOS and visionOS only)

Pitfalls, Performance, and Testing ​

  • Scroll view conflicts, missing coordinate spaces, and rebuilding what Button provides
  • Keeping onChanged light, and using transactions for smooth animation
  • Troubleshooting, UI tests for gestures, and a manual checklist

Documentation Scope ​

This page documents the gestures skill (in the axiom-swiftui suite), which your assistant loads when you implement or debug gestures. The skill has the code for each pattern, with wrong and right versions.

  • accessibility-diag – Finding and fixing controls that VoiceOver users can't operate
  • touch – Touch on touch-display Macs and Sidecar, including AppKit
  • swiftui-performance – When a gesture-driven animation drops frames
  • ui-testing – Testing gesture interactions

Resources ​

WWDC: 2019-237, 2020-10043, 2021-10018

Docs: /swiftui/composing-swiftui-gestures, /swiftui/gesturestate, /swiftui/gesture, /swiftui/hoverphase

Released under the MIT License