Select Page

Force Touch – now 3D Touch

by September 14, 2015Development

With approaching release of iPhone 6s and iOS 9, there was a lot of talk about a new feature called Force Touch. As it turns out, after iPhone 6s announcement it’s marketing name is 3D Touch. Golden master release of Xcode 7 already includes 3D Touch APIs, however it is currently impossible to test the APIs on the iOS Simulator.

But that does not stop some developers (including me) from having a look. From the initial Adopting 3D Touch document posted by Apple, we can see there are 3 ways to implement 3D Touch in an application.

  • Home Screen Quick Actions
  • UIKit Peek and Pop
  • Force Properties in UITouch Objects

For me, the most interesting way was of course with UITouch objects, since they are delivered directly on UIView, through three methods:

  • touchesBegan:
  • touchesMoved:
  • touchesEnded:

What surprised me was that no UIGestureRecognizer classes were implemented to make it easier for developers to integrate custom 3D Touch actions. Being interested in the details, I decided to give it a try to implement my own.

There are two properties added to UITouch in iOS 9: force and maximumPossibleForce. In iOS 9.1 we will also get a couple new more, mostly to support Apple Pencil functionality (altitudeAngle, azimuthAngleInView, estimatedProperties, …).

However, the document does not explain how exactly to use those properties and since it is impossible to test, we are just guessing here. All we know is that force of 1.0 is an average press and should probably be considered a normal tap.

So, I wrote a basic tap gesture recognizer in Swift that supports both shallow and deep touches. Each UITouch object received is checked against this function:

The logic is pretty simple. We calculate a difference based on average force and maximum possible force and separate the rest into two sections. We allow the developer to specify which touch to recognize and we stored that in touchType property.

Full project is available on GitHub and also includes an example.

To support all variants of force touches, such as force-pan or force-swipe, other gesture recognizers will have to be implemented. For now, only force tap is supported.

Maximum possible force on iPhone 6s is 6.6667, according to maximumPossibleForce property. I will update the project to use the values Apple uses for peek and pop.

3D Touch opens a whole new category of applications on iOS and I am really looking forward to it being used across multiple applications on iOS.

Also added support for 3D Touch to Alpha, so you can see touches on screen. Check out Touch Plugin wiki for detailed explanation.

dal_face  DAL RUPNIK
  Founder of Unified Sense, tweeting at @thelegoless.