Making a zoomable Image, in SwiftUI
Welcome to this tutorial on creating a zoomable image in SwiftUI! If you've been struggling with various options for creating a zoomable image in SwiftUI, you're not alone.
While there are many solutions, some require tons of boilerplate, and others only work in UIKit. Some, finaly, simply work, until they don't run on UIKit. Others work, until they don't.
Having tried those, and looked into a few libraries (I especially liked this one, until I realised it would only stay zoomed in as long as you were actually pinching), I can say JarWarren and Haolong were right. (Un)surprisingly, turning our image into a PDF document and displaying it using PDFKit
is the simplest way I've found so far to make a zoomable Image
you can pan around in SwiftUI (using UIViewRepresentable
).
For those of you struggling with it, here's my take on it (careful, it seems PDFKit has it's own weird quirks):