Media · 8 free pieces

SwiftUI photo and media components

A full-screen photo viewer with pinch to zoom, a photo cropper, and a Stories-style progress strip with hold to pause.

All components

About these pieces

One self-contained Swift file each, Apple frameworks only, from iOS 17.

Photo Viewer is a full-screen photo surface with anchor-correct pinch zoom, momentum panning that settles into the bounds, double-tap zoom about the tap, paging between images, and pinch-out or drag-down to dismiss.

Story Strip is a Stories-style segment strip with a built-in clock, a long-press hold that pauses it, tap zones for back and forward, and a manual progress mode when you own the timing.

Photo Cropper is the crop step after picking a photo: the photo always covers a frame of the chosen aspect, pinch zooms around the fingers while it pans, limits rubber-band, quarter turns keep the subject in frame, and the crop renders off the main thread at the original's full resolution.

Learn the technique: SwiftUI animations guide.

Questions

How the pieces work, and how to build the same thing yourself. Every piece's page has its full notes.

How do I crop an image in SwiftUI?

SwiftUI has no cropper. Show the photo under a fixed frame, keep its scale and offset clamped so it always covers the frame, then draw the original into a renderer at the frame's rect in the photo's own pixels. Photo Cropper does this with aspect presets, rotation and correct orientation.

How do I add pinch to zoom on an image in SwiftUI?

Combine MagnifyGesture for scale with a DragGesture for panning, anchor the zoom at the pinch location, and clamp the offset to the image bounds. Photo Viewer handles all of that plus double-tap zoom and paging.

Ready to build something better?

85 pieces, one file each, yours to keep. Start with the library or see what the whole app looks like.