Skip to content

Instantly share code, notes, and snippets.

@y8k
Created October 27, 2015 05:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save y8k/9e203413b10f16e9bd5b to your computer and use it in GitHub Desktop.
Save y8k/9e203413b10f16e9bd5b to your computer and use it in GitHub Desktop.
Implementation Peek for 3D Touch
func previewingContext(previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
guard let indexPath = self.tableView.indexPathForRowAtPoint(location), cell = self.tableView.cellForRowAtIndexPath(indexPath) else { return nil }
let selectedData = self.data[indexPath.row]
var detailViewCntrlr: UIViewController?
switch selectedData.type {
case .List:
detailViewCntrlr = self.storyboard?.instantiateViewControllerWithIdentifier("DETAIL_LIST_SCREEN")
break
case .Web:
detailViewCntrlr = self.storyboard?.instantiateViewControllerWithIdentifier("DETAIL_WEB_SCREEN")
break
case .Content:
detailViewCntrlr = self.storyboard?.instantiateViewControllerWithIdentifier("DETAIL_CONTENT_SCREEN")
break
}
guard detailViewCntrlr != nil else { return nil }
detailViewCntrlr!.preferredContentSize = CGSizeMake(0.0, 0.0)
previewingContext.sourceRect = cell.frame
return detailViewCntrlr
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment