A class that registers a view to provide a custom user experience in response to 3D Touch interactions.


class UIPreviewInteraction : NSObject


A 3D Touch interaction results in a preview interaction that comprises two phases, the first also called preview, followed by commit. The interaction progresses through these phases as the user applies more force with a touch. Figure 1 shows the relationship between the force of the user's touch and the phases of the preview interaction.

Figure 1

Relationship between touch force and preview interaction phases

An illustration showing the preview interaction as it progresses through the preview phase and into the commit phases in response to increasing touch force.

When using view controller previewing, peek represents the preview phase, and pop the commit phase.

A preview interaction is responsible for managing 3D Touch interactions for a specified view. It uses a delegate object to communicate the progress and status of the interaction to your code.

To use a preview interaction in your app:

  1. Create a UIPreviewInteraction object, passing the view into the default initializer.

  2. Create a delegate object that conforms to the UIPreviewInteractionDelegate protocol, and implement the appropriate methods.

  3. Assign the delegate object to the delegate property on the preview interaction object.

For more information about the state transitions through which a preview interaction progresses, see UIPreviewInteractionDelegate.


Preparing Preview Interactions

init(view: UIView)

Returns a newly initialized preview interaction for the specified view.

var delegate: UIPreviewInteractionDelegate?

An object that acts as the delegate of the preview interaction.

Handling Preview Interactions

var view: UIView?

The view from which the preview interaction receives touch events.

func cancel()

Cancels the current preview interaction.

func location(in: UICoordinateSpace?) -> CGPoint

Returns the location of the touch that started the interaction.


Inherits From

Conforms To

See Also

3D Touch Interactions

protocol UIPreviewInteractionDelegate

A set of methods for communicating the progress of a preview interaction.

protocol UIPreviewActionItem

A set of methods that defines the styles you can apply to peek quick actions and peek quick action groups, and defines a read-only accessor for the user-visible title of a peek quick action.