Serghei Catraniuc Serghei Catraniuc - 2 months ago 38x
iOS Question

Retrieve UIPreviewInteraction associated touch

I'm using the new UIPreviewInteraction API and want to know the location where the user lifts up his finger.

Basically the flow that I want to create is:

  1. User 3D touches on something.

  2. Bubbles appear around his finger.

  3. User slides his finger on top of one of them.

  4. Lifts his finger and the app registers his selection.

The UIPreviewInteraction API doesn't have a reference to the UITouch that initiated the interaction.

Is there another way to get it?


Alright, turns out I was going about it the wrong way.

I was trying to receive touch updates in the previewInteraction:didUpdatePreviewTransition:ended: method

But there you'll only receive updates until the 'peek' is happening. After it ends, you no longer receive any updates.

However, if you override the previewInteraction:didUpdateCommitTransition:ended: method you'll continue receiving touch location updates there using this code:

CGPoint touchPoint = [previewInteraction locationInCoordinateSpace:previewInteractionView];

You can find sample code from the Apple WWDC video here