Create Instagram’s Pinch to Zoom using Swift

Lightbox? No problem

Steven Curtis
3 min readMay 7, 2021
Photo by Ksenia Makagonova on Unsplash

Difficulty: Beginner | Easy | Normal | Challenging

This article has been developed using Xcode 12.5, and Swift 5.4

The supporting video for this article is available at: https://youtu.be/vm6sQAN3KNU

Prerequisites:

Terminology

UIGestureRecogniser: The base class for gesture recognisers, which include tap and pinch recognisers

UIPinchGestureRecognizer: A concrete subclass of UIGestureRecogniser

The Goal

Instagram is Great!

When you scroll up and down, the images in an apparent UICollectionView display. If you pinch an image it gets larger on the screen, and the background fades to black.

Can we somehow use a UICollectionView to do the same?

The approach

The technique used in this implementation is to subclass a UICollectionViewCell and if the cell itself is pinched add an overlay UIView to UIApplication.shared.windows (it is…

--

--