I sort of couldn't believe this was an actual issue, but it seems to be impossible to create a pure SwiftUI view that pans and zooms at the same time!
This is one of the core multitouch behaviors which Apple has supported in Photos, Maps and Safari for fourteen years. Every Apple app which supports zooming an image also supports simultaneous panning.
I filed this serious UI bug as FB9488452 with the following sample code:
struct ContentView: View {
@GestureState var zoom = CGFloat(1.0)
@GestureState var pan = CGSize.zero
var body: some View {
VStack {
Image(systemName: "person")
.font(.largeTitle)
.padding()
.foregroundColor(.black)
}.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.white)
.scaleEffect(zoom)
.offset(pan)
.animation(.spring())
.gesture(
MagnificationGesture().updating($zoom){ (value, state, transaction) in
state = value
}.simultaneously(with: DragGesture())
.updating($pan){ (value, state, transaction) in
state = value.second?.translation ?? .zero
print("Translation: \(value.second?.translation ?? .zero)")
}
)
}
}
The above code should compose a gesture which allows simultaneous dragging and zooming, but only one of the gestures will succeed. It's as if they have been specified as Exclusive rather than Simultaneous. This is clearly a bug, as these gestures should absolutely be able to compose.