3D touch/Force touch implementation

Avi Rok picture Avi Rok · Sep 25, 2015 · Viewed 18.7k times · Source

How can we implement 3D touch to check if the user taps on UIView or force touch on UIView?

Is there a way to do this with UIGestureRecognize or only with UITouch?

Answer

random picture random · Oct 6, 2015

You can do it without a designated gesture recognizer. You do not need to adjust the touchesEnded and touchesBegan method, but simply the touchesMoved to obtain the correct values. getting the force of a uitouch from began/ended will return weird values.

UITouch *touch = [touches anyObject];

CGFloat maximumPossibleForce = touch.maximumPossibleForce;
CGFloat force = touch.force;
CGFloat normalizedForce = force/maximumPossibleForce;

then, set a force threshold and compare the normalizedForce to this threshold (0.75 seems fine for me).