kbpontius kbpontius - 1 year ago 100
iOS Question

3D Touch Peek Swipe Like Mail

Using the 3D Touch Peek and Pop functionality, what is the most effective way of mimicking the capability depicted below (to swipe the "peeked" content side-to-side to perform an action)? The screenshot below comes from the iOS native Mail app.

Mail Swipe 3D Touch - Unread
Mail Swipe 3D Touch - Trash

Answer Source


You can replicate this effect on iOS 10. There's a new set of APIs called UIPreviewInteraction and UIPreviewInteractionDelegate that enable custom presentation for peek/pop interactions. I highly recommend watching A Peek at 3D Touch from this year's WWDC.

Original Answer

Looking at the iOS Runtime Headers, there's a class called UIPreviewPresentationController. That's the controller responsible for peeks. Inside it, there are references to objects called leadingPreviewAction and trailingPreviewAction. These have corresponding properties that deal with edge constraints and centers. Judging by use of the terms leading and trailing (as in Auto Layout), these may correspond to left/right action items.

This is speculation, but I think these related private classes (_UIPreviewQuickActionView) control the behavior you're looking for. Those are unavailable right now.

Likewise, the documentation for UIPreviewAction says:

A preview action, or peek quick action, is displayed below a peek when a user swipes the peek upward. A peek quick action typically selects a deep link to your app and has a title, a style, and a handler.