iosxcodeswiftios9peek-pop

Implement 3D Touch "Peek and Pop" for Manual Segue


I'm trying to figure out how to implement the "Peek and Pop" 3D touch feature for an application I'm working on, and I'm not sure how to implement that functionality for a manual segue, so any help or documentation would be much appreciated.

To give you a little more information, I have a UITableView who's controller has 2 manual segues that my code picks between depending on what table element the user taps on. If it's one segue I've dragged from the prototype table cell to the target view controller, I can check a box, but that box is not present for manual segues.

I've done a bit of Googling to see if there is documentation on this, but I couldn't find anything.


Solution

  • Per the UIViewControllerPreviewingDelegate Reference, implement

    func previewingContext(_ previewingContext: UIViewControllerPreviewing,
      commitViewController viewControllerToCommit: UIViewController)
    

    Implement this method to configure and present the commit (pop) view controller, in a way that is appropriate for your app.

    For example, to present the commit view controller’s view in a navigation controller, call the navigation controller’s showViewController:sender: method; to present the view modally, you could call the presentViewController:animated:completion: method.

    So inside your implementation you can say:

    func previewingContext(previewingContext: UIViewControllerPreviewing,
          commitViewController viewControllerToCommit: UIViewController){
          self.navigationController.showViewController(viewControllerToCommit,sender:self)
    }
    

    Or

    func previewingContext(previewingContext: UIViewControllerPreviewing,
          commitViewController viewControllerToCommit: UIViewController){
          self.navigationController.pushViewController(viewControllerToCommit,animated:true)
    }
    

    if you're more comfortable with that.