Search code examples
iosuikituitouch

How to work with 3D Touch in iOS 9? Does it trigger event when pressure changes?


I wonder if I can detect continuously changing pressure of user input on iPhone 6s.

With simple touch it's obvious, from the UIResponder you can hook into touchesBegan and TouchesMoved and you'll have the coordinates every time when the user touches the screen and when moves his/her finger, you can have the current position on every update.

However, I'm not sure how the new :force property works. If you read the "force" in touchesBegan, wouldn't you get some minimal pressure value that was detected at the initiation of the touch?

Is there a way to get update on the force value as it changes, just like the touchesMoved? Maybe there is a method like "forceChanged"?


Solution

  • From the iOS 9.1 Release Notes

    On 3D Touch capable devices, touch pressure changes cause touchesMoved: to be called.

    Apps should be prepared to receive touch move events with no change in the x/y coordinates.

    This means that a touchesMoved: callback either indicates a continuous change in force or location or both!

    Hopefully this information will one day make it into the UITouch documentation.