Is 3D Touch Peek & Pop removed?

I have code that I have not changed for quite some time.


Repos history verfies that.


It used to provide peek & pop on a tableview until very recently.


Now it does nothing.


Has this functionality disappeared from iOS?


If so, can you please advise a link to that effect?


Thank you!

Replies

Anyone know?

Specifically, it seems gone in my table view, but in other places seems to work.

No, I've seen nowhere it was removed !


Just a check : have you set the settings:

Touch in Settings > General > Accessibility > 3D Touch


Probably yes if it works elsewhere.


Have you registered the UIViewController for peek and poke ?

Working With 3D Touch Previews and Preview Quick Actions (from UIViewController documentation)

The methods in this task group are available on devices that support 3D Touch. The end-user terminology for the views presented during the phases of force-based touches includes peek and pop. For clarity here, and to align with the API names, this document uses the corresponding terms preview and commit view. To learn more about 3D Touch, read Adopting 3D Touch on iPhone.


func registerForPreviewing(with: UIViewControllerPreviewingDelegate, sourceView: UIView)

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



Can also look at this tutorial :

h ttps://blog.zaven.co/3d-touch-peek-pop-tutorial/

Hi Claude,


Thanks for the reply!


I did in fact check the settings but all was fine there. And, like I metioned, I did not change any code. Here's my setup:


- (BOOL)isForceTouchAvailable {
    
    BOOL isForceTouchAvailable = NO;
    
    if ([self.traitCollection respondsToSelector:@selector(forceTouchCapability)]) {
        isForceTouchAvailable = self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable;
    }
    return isForceTouchAvailable;
}

- (UIViewController *)previewingContext:(id )previewingContext viewControllerForLocation:(CGPoint)location{
        // check if we're not already displaying a preview controller
    if ([self.presentedViewController isKindOfClass:[AWDetailsViewController class]]) {
        return nil;
    }
    
    CGPoint cellPostion = [self.tableView convertPoint:location fromView:self.view];
    NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:cellPostion];
    
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    
        // set the view controller by initializing it form the storyboard
    AWDetailsViewController *previewController = [storyboard instantiateViewControllerWithIdentifier:@"awDetailsViewControllerSBID"];
    
    NSString* dateString = [self.sortedDays objectAtIndex:indexPath.section];
    NSArray* currentSection = [self.sections objectForKey:dateString];
    
    AWItem* awItem = currentSection[indexPath.row];
    previewController.selectedAWItem = awItem;
    
    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
    previewingContext.sourceRect = cell.frame;
    
    return previewController;
}

- (void)previewingContext:(id )previewingContext commitViewController: (UIViewController *)viewControllerToCommit {
    
    [self.navigationController showViewController:viewControllerToCommit sender:nil];
}

- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
    
    [super traitCollectionDidChange:previousTraitCollection];
    
    if ([self isForceTouchAvailable]) {
        if (!self.previewingContext) {
            self.previewingContext = [self registerForPreviewingWithDelegate:self sourceView:self.tableView];
        }
    }
    else {
        if (self.previewingContext) {
            [self unregisterForPreviewingWithContext:self.previewingContext];
            self.previewingContext = nil;
        }
    }
}

And in viewDidLoad I do this:

if ([self isForceTouchAvailable]) {
        self.previewingContext = [self registerForPreviewingWithDelegate:self sourceView:self.tableView];
}


And the class utilizes this protocol: UIViewControllerPreviewingDelegate


I'm kinda stumped... I'm using an iPhone X by the way.


Thanks again for your help and I will look at your tutorial!

You registered in viewDidLoad, that should work.


Some ideas:

- did you set the sourceRect :

previewingContext.sourceRect = tableView.frame

- could you try registering the complete view instead of tableView, just to see if tableView reacts to this.


I found this complete code sample:

h ttps://github.com/quentinR/PI3DTouch

HI Claude.


Yes.


I set it like so:

previewingContext.sourceRect = cell.frame;


But I also tried self.view and self.tableview


"Could you try registering the complete view instead of tableView, just to see if tableView reacts to this."


Tried that as well.


Still does not work.


Thank you very much!


I will also look at the example you linked to.

So, I think I figured out how.


Just don't understand why.


self.navigationItem.searchController = self.searchController;


If I add that line, 3D Touch does not work on my tableview.


I want my app to have a search controller (with scopebar) but it seems that 3D Touch and search are incompatible?


Any ideas why this might be the case?


Thanks!