How to implement 3D-Touch Peek-and-select?
Asked Answered
H

3

9

Phone, Reminders, and Maps use a different 3D-Touch Peek UI allowing to select an action in one go. For instance, force-press on a reminder and select "Remind me on a day" in one go, without releasing the finger. It also differs visually from standard 3D Touch previews using the UIViewControllerPreviewing API as it displays a custom icon alongside left-aligned text.

enter image description here

I couldn't find a way to do this using the official API. Did I miss something or is this a private API indeed?

Haubergeon answered 29/9, 2015 at 10:34 Comment(1)
Please consider marking my answer as correct to ensure people find the relevant source quickly. Thanks!Loewi
H
3

I asked my question on the Apple Developer Forums as well and received this reply from Apple:

Currently there is not public API to do these things. Please file bug reports if this is something you want to do in your app, and include specific details of what you're looking to do.

So it's currently not possible using the official SDK. I filed this enhancement request radar and I encourage you to dupe it if you need this, too!

Haubergeon answered 12/10, 2015 at 20:43 Comment(0)
L
2

For future readers, the response from Apple for this question is:

Currently there is not public API to do these things. Please file bug reports if this is something you want to do in your app, and include specific details of what you're looking to do.

Source: Apple Developer Forum

Loewi answered 8/10, 2015 at 11:12 Comment(0)
S
-1

Those are UIPreviewActionItem.

After overriding previewingContext:viewControllerForLocation: you can also override - (NSArray<id<UIPreviewActionItem>> *)previewActionItems and that will allow you to specify your quick actions.

Here's a snippet that will help you out: (related tutorial)

- (NSArray<id<UIPreviewActionItem>> *)previewActionItems
{
    UIPreviewAction *action1 = [UIPreviewAction actionWithTitle:@"Action 1" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
        NSLog(@"Action 1 triggered");
    }];

    UIPreviewAction *action2 = [UIPreviewAction actionWithTitle:@"Destructive Action" style:UIPreviewActionStyleDestructive handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
        NSLog(@"Destructive Action triggered");
    }];

    UIPreviewAction *action3 = [UIPreviewAction actionWithTitle:@"Selected Action" style:UIPreviewActionStyleSelected handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
        NSLog(@"Selected Action triggered");
    }];

    return @[action1, action2, action3];
}

Apple Docs:

This property is for use with a preview (peek) view controller which you present in your implementation of the previewingContext:viewControllerForLocation: delegate method..

Implement this method to provide quick actions for such a preview. When the user swipes upward on the preview, the system presents these quick action items in a sheet below the preview.

The default implementation of this method returns an empty array.

Sistrunk answered 1/10, 2015 at 18:27 Comment(2)
Please read the question carefully. I'm not referring to the standard Peek-and-Pop previews but to the special ones in the mentioned apps. The standard previews don't allow you to select an action without releasing the finger.Haubergeon
How would you use this to compose mail? I have in my Preview Controller a standard displayComposerSheet method, but when I tell the action to do that, the composer never displays, since the method tells it to launch in that preview, and the preview is no longer there.Pasty

© 2022 - 2024 — McMap. All rights reserved.