Last active
February 15, 2016 19:31
-
-
Save danielgalasko/bf4a189a3cd356216034 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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