3D Touch Peek and Pop iOS-Swift 4.2

Sandeep Kumar
2 min readOct 7, 2018

As you all are familiar with the 3d touch introduced by Apple in it’s iOS devices, if not then follow the link: https://developer.apple.com/ios/3d-touch/

If you are one of them who are big fan of Instagram UX of previewing the images in search screen and little bit of swiping up to see action sheet with options of ❤️ or REPORT etc. then this article is for you.

We are going to start by creating a simple project and creating a grid of 3X3 using collection view in a viewcontroller named MainVC (MainVC.swift), here is the preview of simple viewcontroller screen that you all can make easily.

Now write the following code in viewDidLoad() of MainVC to first check if the device support 3dTouch (force touch) and if supports then register the view on which you want to use 3dTouch and applying UIViewControllerPreviewingDelegate to MainVC.

After that extend your MainVC class to UIViewControllerPreviewingDelegate.

Now create a PreviewVC for previewing the peeking UIViewController on first hard press and DetailVC for final full detail on second hard press in continuity. You can set size of PreviewVC by setting the preferred content size of UIViewController.

Left(PreviewVC) — — — — — — — — — — — -— — — — — -Right(DetailVC)

Now write the following code inside UIViewControllerPreviewDelegate functions.

if you want to add some more feature to peek like ActionSheet for some options then override the previewActionItems variable in PreviewVC.

Now we have to pass reference of MainVC to PreviewVC if you want to push any viewcontroller further on tap of previewActions otherwise not required.

So here is the code that you have to write in PreviewVC.

Here is what we got………

Github Link:- https://github.com/SandeepSpider811/3DTouchTemplate

--

--