2026 • macOS • 13:19
Discover how to add touch capabilities to your Mac app. Explore how to transition from classic mouse tracking APIs to modern gesture recognizers and touch-native controls. Find out how to optimize hit targets, implement multi-touch interactions, and manage system gestures to deliver an incredible touch experience. To get the most out of this session, watch Design for Touch on Mac.
Speaker: Raleigh Ledet
Downloads from Apple
Transcript
Too hot! Too hot! Oh no! Get the burners down! Get the burners down! Okay, get that one! Get this one! Get the other one! One more to go! Oh! Mais, that was intense! Ah, comment ça va? I’m Raleigh Ledet, an AppKit Engineer, and I was just testing out the game I’m working on with the new Mac with Touch Display. The new Mac with Touch Display opens up new interaction possibilities. Join in with me and T’ Thib as I update my game for first-class touch support.
The good news is that we’ve already made touch work great out of the box for all apps. Across our native frameworks, standard components just work with native touch. Existing gestures created in SwiftUI just work. But if you have a specialized need to distinguish between mouse and direct touch input, you can use the new GestureInputKinds gesture modifier API. Existing gestures created in Mac Catalyst just work. And if you have a specialized need to distinguish between mouse and direct touch input, you can use the existing UITouch.touchType and UIGestureRecognizer’s allowedTouchTypes APIs.
AppKit has adopted gesture recognizers for both mouse and touch input. Standard buttons, controls, tables, collections, split views, tabs, scrolling, and more are all touch native. But for existing custom AppKit mouse interactions, or if you use non-Apple UI frameworks, AppKit intelligently emulates the mouse, but with a little polish and AppKit’s rich toolset, you can create a great touch experience without performing a user interface overhaul, which is what I’m going to do with my game. As an AppKit app, the best way to become touch native is to use standard AppKit controls and views without overriding mouseDown(with:). Often, your goal can be accomplished with delegate methods or control events without the need to subclass and override mouseDown(with:).
Take the burner ignition buttons as an example. These are plain NSButtons. As the player holds the button, the burner starts to spark. The player needs to hold the button long enough to light the burner, but hold for too long and the ignition circuit will overload. Previously, to accomplish this, I subclassed NSButton and overrode mouseDown(with:) to tell the oven controller when the button tracking starts and ends. The player can touch the screen and the buttons work, but AppKit must emulate mouse events to pass to the mouseDown override. Instead, I’m going to switch to NSControl events directly on NSButton without the need to subclass.
With control events, it’s easy to tell when the player begins or enters tracking, exits or ends tracking, and I can now detect the important canceled tracking. If tracking is canceled due to a system gesture like Exposé, scroll, or any other reason, I can revert any unintended changes. NSControl events are available for standard AppKit controls, and most control events are available all the way back to macOS 11. See the WWDC26 session “Modernizing your AppKit app” for more information.
One of the many challenges in my game is to rewire a panel by dragging from one colored point to the matching point on the other side. Previously, I accomplished this with a custom NSView with a mouseDown(with:) override that uses the standard tracking loop technique. That is, calling nextEvent(matching:) in a loop until I receive a mouseUp event.
If you’re familiar with SwiftUI or UIKit, you may notice an inconsistency with how events are tracked. Starting with macOS Golden Gate, gesture recognizers are the preferred approach in AppKit. Indeed, gesture recognizers have become the shared input language across SwiftUI, Mac Catalyst, and now AppKit. In fact, gesture recognizers are the only way to get direct touches on macOS. Migrate your mouse tracking loops to gesture recognizers. Often, the same gesture recognizer can be used for both mouse and touch input.
That said, tracking loops are still supported and can coexist with touch-only gesture recognizers. You may find that adding touch-only gesture recognizers is the fastest and least risky path for a dot release of your app. The first step is to refactor my tracking loop into separate start, continue, end, and cancel tracking functions. Now, the mouse tracking loop and the touch gesture recognizer can both route to the same underlying tracking logic. With the mouse tracking refactor complete, I can set up a touch-only NSPanGestureRecognizer. To do this, set the buttonMask to 0 and allowedTouchTypes to .direct on an initialized NSPanGestureRecognizer.
With my pan gesture recognizer set up, I’ll add it to the wiring panel view. When a pan gesture recognizer recognizes, its state property will flow from .began to .changed to .ended, calling its action message over and over as its properties change. In my touchPanAction function, I call the appropriate refactored tracking function for the current gesture state. For example, when the pan gesture state is .began, I call the startTracking function. Let me give it a try. Works with the trackpad. Now I’ll try touch.
Hmm, I can get it to work, but it’s a little tricky to touch the small hit target of those nodes. Let me see what I can do. This is the startTracking implementation where I iterate over the wiring nodes to find which node, if any, contains the view location. But the frame of each node is pretty small. And as discussed in “Design for touch on Mac,” touch targets on macOS should have a minimum size of 36 points.
Instead of changing the size of the nodes, I’ve added an optional expandHitRect parameter to the startTracking function. I set expandHitRect to true when startTracking is called on the touch-only pan gesture recognizer action. My helper function then expands the size of the target rect to a minimum of 36 points on each axis.
This makes it easier for a touch to hit a node while still requiring the mouse to be precise and without modifying the layout of the wiring panel. This is a particularly useful technique for small resize, or grab, handles for selected objects in a canvas view. I’m going to give it another try.
Much better. I highly recommend watching the “Design for touch on Mac” talk for more design guidance for adding touch to your app. The decorating mini game is another interesting place for an improved touch experience. Normally, a player wants to scroll using a single finger. However, in this mode, the player expects to use a single finger to apply a custom piping to the candy. For this special use case, I’ll set the decorating view’s enclosing scroll view to require two touches minimum for touch scrolling. Now I can add my signature R for Raleigh with one finger. Scroll around with two fingers, add some pizzazz. Yum!
I want to return to the gas flow sliders. This is the heart of the game where the player needs to manage the burner output under different scenarios to match the recipe instructions. Too hot for too long and the batch is ruined. These are standard NSSliders, so they are already touch native. But I can only drag one slider at a time.
This is called gesture exclusivity. By default, only one view can be interacted with at a time. Gesture exclusivity allows the gesture recognition system to emulate modal tracking loops. Otherwise, unsuspecting apps may get confused when multiple controls are simultaneously manipulated. You can incrementally turn off gesture exclusivity as portions of your app become multi-input compatible.
For example, AppKit does this in the standard color panel, where you can adjust multiple sliders at the same time. The API to control gesture exclusivity is the exclusiveGestureBehavior property on NSView, which is available in the next SDK. By default, it inherits its parent’s exclusive gesture behavior. By setting the exclusiveGestureBehavior property on the stove view to .notExclusive, the child slider subviews all become non-exclusive as well, and the player can now adjust multiple burners at the same time.
Much better. Now I can move two sliders at once. But I’ve noticed, if I try to control three or more sliders in the same direction at the same time, I get the system gesture instead of controlling the sliders. I can control system gesture availability at the window level with the disablesDirectTouchSystemGestures property on NSWindow. SwiftUI and Mac Catalyst also have similar API on UIViewController and View.
Use great care when it comes to disabling system gestures. Only disable system gestures if the interaction capabilities they open up are critical for the window. In this case, my game has a high-intensity scenario, and if the player doesn’t lower the burners fast enough, they will lose the game. Accidentally triggering a system gesture during this critical part of gameplay can cost the player precious seconds, so I’ll disable the system gesture only when the gas burners are visible. And perhaps only when this extreme scenario is in play. I’m going to try that overheating scenario again.
Crisis averted. This is a nice change and really adds to the immersion of candy making. We’ve covered a lot, from refactored tracking loops so it can be used with both mouse tracking and a touch gesture recognizer, and modifying how scrolling interacts with touch, to expanded hit testing, gesture exclusivity, and even how to disable touch gestures when critical. These are just a few of the techniques that you can use in your apps. But before you go, I want to provide you with a few more quick tips for drag and drop, context menu support, hover controls, and non-Apple UI frameworks.
When a draggable item is long pressed, it should hint at its draggability with a lift animation. To get the drag-and-drop lift preview, use the existing drag-and-drop delegate APIs on NSTableView, NSOutlineView, and NSCollectionView. These container classes automatically know what to do. Similarly, a long press is often used to display a context menu. Use the menu property on NSView or override menu(for:).
AppKit will detect this and automatically install the appropriate gesture recognizers, which include a control-tap gesture recognizer as an accelerator to display your context menu. When using both this menu API and the container view drag-and-drop delegate APIs, AppKit will coordinate when a long press becomes a drag-and-drop operation or a context menu one, even allowing the user to switch between them.
Direct touches don’t have an equivalent to mouseMoved events. Thus, special consideration is needed for user interface elements that reveal on mouse hover, also known as rollover. In general, don’t change your app experience to permanently show hidden controls. Static data like tooltips shouldn’t be revealed on touch. But for hidden essential controls, install a touch-only click gesture recognizer to temporarily show the element on a touch tap. Again, watch the “Design for touch on Mac” video for a more detailed discussion. If AppKit determines that your application uses a non-Apple UI framework, a special set of mouse emulation tactics are enabled.
Since AppKit can’t determine what kind of interactions are allowed at any particular location of your non-Apple UI framework content, a generic set of mouse emulations are applied to each window. This allows for a one-finger scroll with momentum, click, drag with a small hold delay, and even pinch for rotation and magnification. While this allows users to control your app with touch, adding native touch support allows you to really dial in the user experience.
As you add native touch support, add an NSIsTouchNative entry to your Info.plist to let AppKit know you are touch native and no longer need the non-Apple UI toolkit mouse emulations. You don’t even have to wait until your very own Mac with Touch Display is delivered. With the latest macOS beta and developer tools, all the touch features of the Mac with Touch Display are available with an iPad connected to your Mac with Sidecar. The fastest way to get started with touch on Mac is with the Sidecar tools you already own.
Plus, with the latest developer tools, there’s a gesture modernization skill that has an understanding of the features and changes I’ve talked about. Be sure to check it out. So start testing your application with touch on macOS with Sidecar. Then audit your code for mouseDown(with:) overrides. Determine if you can use control events or delegate methods instead, or if you need to add your own touch-specific gesture recognizers. Look for areas that have small hit targets and expand them for touch. And finally, add an affordance or use a tap to reveal essential hidden UI.
With macOS’s direct touch APIs, it’s easy to let people get in touch with your application on the all-new Mac with Touch Display. And with just a sprinkle of touch-specific support for your unique UI, your app will be a touch ahead of the competition. And while you’re doing that, me and T’ Thib, we’ll be working on our next recipe.