I am exploring the use of drag gestures.
Below is a small test code to see what happens and because I want to know the location on the screen / map.
The first time I drag, it works fine, but when I try to drag again, the object jumps around and I get screen locations that are completely wrong.
I want to drag the object and, after stopping, continue dragging it further.
Ultimately, the code will be used, in part, in an app with a map.
import SwiftUI
struct ContentView: View {
@State private var offSet: CGSize = .zero
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
.offset(x: offSet.width, y: offSet.height)
.gesture(
DragGesture()
.onChanged({ value in
offSet = value.translation
})
.onEnded({ value in
offSet = value.translation
print("Location stopt: \(value.location)")
})
)
}
.padding()
}
}
#Preview {
ContentView()
}