Skip to content

Instantly share code, notes, and snippets.

@danielgalasko
Last active February 15, 2016 19:31
Show Gist options
  • Save danielgalasko/bf4a189a3cd356216034 to your computer and use it in GitHub Desktop.
Save danielgalasko/bf4a189a3cd356216034 to your computer and use it in GitHub Desktop.
@available(iOS 9.0, *)
extension TwitterFeedViewController: UIViewControllerPreviewingDelegate {
public func previewingContext(previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
guard let indexPath = collectionView.indexPathForItemAtPoint(location),
cell = collectionView.cellForItemAtIndexPath(indexPath),
let tweet = viewModel.tweetAtIndexPath(indexPath) else { return nil }
//now we are ready to create our corresponding controller for the tweet
let tweetViewController = self.navigationCoordinationController.tweetControllerForTweet(tweet)
//I will expand on this in a bit but this lets us present controllers using peek and pop actions
tweetViewController.initiatingPreviewActionController = self
//lets the system dictate the size
tweetViewController.preferredContentSize = CGSize.zero
//Shows the tweet controller right over our cell. Changing this will change where the controller is peeked from.
tweetViewController.sourceRect = cell.frame
return tweetViewController
}
public func previewingContext(previewingContext: UIViewControllerPreviewing, commitViewController viewControllerToCommit: UIViewController) {
showViewController(viewControllerToCommit, sender: nil)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment