3

The Apple Maps app allows for simultaneous two-finger drag and magnification. I have tried implementing this functionality with SwiftUI gestures. Simultaneous rotation and magnification works as expected, but simultaneous drag and magnification does not. Maybe there is a way to conform to the Gesture protocol for custom behavior?

Brett
  • 491
  • 4
  • 9
  • For anyone where the gestures are not working. Make sure that the `.roationEffect` (if you use roationgesture) or `.scaleEffect` (for manginifcationGesture) modifiers are placed before the `.gesture `modifier! otherwhise infite loop – charelf Sep 24 '22 at 18:55

2 Answers2

3

I was not able to achieve simultaneous drag and magnification. From my experience DragGesture works only with one touch and ends as soon as there are two touches on the screen. I appears that only gestures requiring the same amount of touches can be simultaneous in SwiftUI. There is also no direct access to touch events to implement custom gesture recognisers. Hope this will change in the future.

SirDeleck
  • 121
  • 1
  • 6
0

I had same question. Check out this solution --> https://betterprogramming.pub/gestures-in-swiftui-e94b784ecc7

He uses: "simultaneously"

        .gesture(MagnificationGesture()
        .onChanged { value in
        self.magnificationValue = value
        }
        .simultaneously(with: RotationGesture().onChanged { value in
                self.rotationValue = value
        }))

Hope this helps.

kopeezie
  • 16
  • 3