Serghei Catraniuc Serghei Catraniuc - 1 year ago 130
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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download