SwiftUI: Error in dragging logic or is this a bug?

DragGesture‘s default CoordinateSpace is .local, which is the coordinate space inside your Circle. What happens when you move the Circle? Since your finger doesn’t move, the location of your finger in the Circle‘s geometry suddenly changes, which causes the Circle to move again. Repeat ad nauseum.

Try using CoordinateSpace.global:

DragGesture(minimumDistance: 10, coordinateSpace: .global)

You’ll probably also want to use value.translation instead of value.location to avoid the initial jump when you put your finger down.

Leave a Comment