Instance Method


Registers a view controller to participate with 3D Touch preview (peek) and commit (pop).


func registerForPreviewing(with delegate: UIViewControllerPreviewingDelegate, sourceView: UIView) -> UIViewControllerPreviewing



The delegate object mediates the presentation of views from the preview (peek) view controller and the commit (pop) view controller. In practice, these two are typically the same view controller. The delegate performs this mediation through your implementation of the methods of the UIViewControllerPreviewingDelegate protocol.


The view, in the view hierarchy of the receiver of this method call, that invokes a preview when pressed by the user.

When lightly pressed, the source view remains visually sharp while surrounding content blurs. When pressed more deeply, the system calls the previewingContext(_:viewControllerForLocation:) method in your delegate object, which presents the preview (peek) view from another view controller.

Return Value

A context object for managing the preview. This object conforms to the UIViewControllerPreviewing protocol.


A preview, or peek in end-user terminology, provides additional content related to the view the user pressed (that is, related to the sourceView view).

Calling this method does three things:

  • Registers the previewing view controller (the one that receives this method call) to participate with 3D Touch preview and commit

  • Designates the source view, from the receiver’s view hierarchy, as the view to respond to a forceful touch

  • Designates a delegate object for mediating the presentation of the preview (peek) and commit (pop) views as a user requests them in turn by pressing more deeply

You can designate more than one source view for a single registered view controller, but you cannot designate a single view as a source view more than once.

The lifetime of this method’s returned context object is managed by the system. If you need to explicitly unregister a view controller, pass its context object to the unregisterForPreviewing(withContext:) method. If you do not unregister a view controller, the system automatically unregisters it when the view controller is deallocated.

See Also

Working With 3D Touch Previews and Preview Quick Actions

func unregisterForPreviewing(withContext: UIViewControllerPreviewing)

Unregisters a previously registered view controller identified by its context object.

var previewActionItems: [UIPreviewActionItem]

The quick actions displayed when a user swipes upward on a 3D Touch preview.