Skip to content

Instantly share code, notes, and snippets.

@shmam
Created January 2, 2024 15:12
Show Gist options
  • Save shmam/33a1ee26002443a87e8e270e818c63a4 to your computer and use it in GitHub Desktop.
Save shmam/33a1ee26002443a87e8e270e818c63a4 to your computer and use it in GitHub Desktop.
Drag Gesture Question
import SwiftUI
struct TestCanvas: View {
@State private var currentGestureLocation: CGPoint = .zero
let colors = [
Color.gray,
Color.gray,
Color.gray,
Color.gray
]
var body: some View {
ZStack {
VStack {
ForEach(colors.indices, id: \.self) { idx in
colors[idx]
.frame(maxWidth: 200, maxHeight: 50)
.overlay(GeometryReader { geo in
Color.clear
.onTapGesture {
}
})
}
}
Circle()
.fill(.green)
.frame(width: 20, height: 20)
.position(currentGestureLocation)
}
.gesture(
DragGesture(minimumDistance: 0)
.onChanged { value in
currentGestureLocation = value.location
}
.onEnded { _ in
currentGestureLocation = .zero
}
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment