iOS how to create interactive transition of image from one view controller to another?

I have a UICollectionView in which each item has a UIImage. When tapping an item, another View Controller gets pushed on the navigation stack. How can I make this so that the UIImage gets passed from the original view controller to the new view controller via an interactive & animated transition? Sort of like the image zooms in from the original view controller's cell item into the new view controller.

I am looking for someway for it to be interactive. Like for example when I tap on the image on the collection view, it zooms in to the new view controller where that image is full screen. However I also want to be able to dismiss this by maybe pinching the image smaller so it goes back to the previous view controller. The current Photos app shows this very well. That's exactly the type of behavior I want.

The new uber app seems to use this in great way on how you can drag things around interactively + animated.

EDIT: I am not looking for someone to spoon feed me the code - I am looking for more general guidelines on how to achieve this in the best possible way. Some way for me to be able to control the entire transition interactively.

Upvotes: 2

Views: 1941

Answers (1)

Harg
Harg

Reputation: 375

You should be able to do this with UIViewControllerAnimatedTransitioning.

In essence you would need to find the rect of the UIIMageView in your UICollectionViewCell and pass that to the custom animator object that implements UIViewControllerAnimatedTransitioning. The animator can then create a new UIImageView of the same image and animate it to move to the rect of where the image will be placed on the newly presented UIViewController.

These tutorials helped me do similar:

Upvotes: 2

Related Questions