By default DragGesture
is created for local namespace, so you get location
as offset from initial position
/// Creates a dragging gesture with the minimum dragging distance before the
/// gesture succeeds and the coordinate space of the gesture's location.
///
/// - Parameters:
/// - minimumDistance: The minimum dragging distance for the gesture to
/// succeed.
/// - coordinateSpace: The coordinate space of the dragging gesture's
/// location.
public init(minimumDistance: CGFloat = 10, coordinateSpace: CoordinateSpace = .local)
but you can also create DragGesture
with global namespace
Rectangle()
.frame(500, 500)
.gesture(
DragGesture(coordinateSpace: .global))
and location in window coordinates. As well you can declare custom coordinate space in some of superview and have drag gesture location in that space
{
// ...
Rectangle()
.frame(500, 500)
.gesture(
DragGesture(coordinateSpace: .named("owner")))
// ...
}
.coordinateSpace(name: "owner")
See the following for example https://stackoverflow.com/a/60495440/12299030