Gestures
Encapsulate your app’s event-handling logic in gesture recognizers so that you can reuse that code throughout your app.
Overview
A gesture recognizer interprets a sequence of low-level events — mouse clicks, touches, or trackpad gestures — as a single, well-defined interaction, such as a click, a press-and-hold, a pan, a pinch, or a rotation, so you don’t have to track events yourself. Attach a gesture recognizer to a view, and it calls your action method when it recognizes that interaction, independent of the responder chain. For more information, see Handling AppKit gestures.
Use one of the standard gesture recognizers when it fits your interaction:
When none of them match the interaction your app needs, define a custom gesture recognizer by subclassing NSGestureRecognizer and use NSGestureRecognizerDelegate to fine-tune how it interacts with other recognizers.
Gesture recognizers are the primary way AppKit, SwiftUI, and Mac Catalyst handle input, and starting in macOS 27 they’re the only way to receive direct touch input from a Mac with a touch display. If your app currently tracks interactions by overriding mouseDown(with:) and related event-handling methods, see Adopting gesture recognizers in your app to learn how to adopt gesture recognizers instead.
Topics
Gesture handling
Standard gestures
NSClickGestureRecognizerNSPressGestureRecognizerNSPanGestureRecognizerNSRotationGestureRecognizerNSMagnificationGestureRecognizer