Force Touch
The force is strong with Apple's new hardware and APIs.
No, it’s not a Star Wars thing; first spotted on Apple Watch, force touch is the umbrella term for pressure sensitivity on touch devices.
On the watch, a force touch (simulated with a long press on the simulator) opens up the context menu. Developers can add up to four menu items here for context-appropriate actions based on whatever’s on the watch display.
Force touch on other touch devices — iPhones and iPads — seemed like a no-brainer. But it turns out the Macs get this new technology next and the iPhone will have to wait a while longer.
What do the force touch APIs look like on OS X? You can get the full details from the documentation linked on Apple’s Force Touch for Developers page, and I’ll hit some of the highlights below.
Gestures and events
NSResponder
and NSGestureRecognizer
have pressureChangeWithEvent:
methods for you to override.
The event passed in will be an NSEvent
object, which has had a pressure
property for a while now; you can get a Float
here with a value from 0–1.0 with the current pressure. Here’s the best line from the API documentation:
Pressure is not intended for measuring weight.
That means you need to shelve that idea for a force-touch trackpad scale app, OK? ;)
stage
is a bit simpler and provides an integer property for gesture events to say whether nothing’s happening (0), it’s a click / mouse down (1) or “additional pressure” aka a force touch (2).
New buttons
OS X 10.10.3 introduces some new button types and functionality:
- Spring-loaded buttons, which provide drag-and-drop on steroids. You can drag something onto a button and then force touch, as if literally drilling down the item into the button.
- Accelerator buttons can either fire events faster the more pressure the user places on the button (useful for media controls) or can be non-continuous and only fire an event when the pressure changes.
- Multi-level accelerator buttons are like sliders with stepped pressure levels. For example, you could set it for three pressure levels and then get an
integerValue
from 1–3. You get a little haptic feedback with each step too.
There’s always a fallback for non-force touch devices: drag-drop-and-wait for spring-loaded buttons, while accelerator buttons will just return a simple on/off or 0/1 value.
Force touch on iOS
What might this look like when force touch makes it to iOS, possibly later this year?
- Haptic feedback – we can make the phone vibrate, but what about a more precise
vibrateWithIntensity:
method? ;) - New gesture recognizer – we already have gesture recognizers for tap and long press, so maybe there will be a new one for force touch. Or, to follow the Watch simulator route, maybe force touch will be an option on the existing long press for backwards compatibility?
- Accelerator buttons – the API for these on OS X looks really neat and there’s a reasonably graceful fallback for non-force touch devices too. Some new properties on
UIButton
or even new methods onUIResponder
would work. - Pressure-related properties on
UITouch
– drawing apps could make good use of a newpressure
property inUITouch
objects. I’m sure the folks at Facebook are already looking to revive their Poke app to support different levels of force to match the poke intensity.