Skip to content

Instantly share code, notes, and snippets.

@darrarski
Last active June 8, 2022 10:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darrarski/c9e7e1e3fa8ddde778fd141d651f01eb to your computer and use it in GitHub Desktop.
Save darrarski/c9e7e1e3fa8ddde778fd141d651f01eb to your computer and use it in GitHub Desktop.
Get location of a tap in SwiftUI
import SwiftUI
struct ExampleView: View {
var body: some View {
Color.blue
.gesture(
TapGesture(count: 1)
.simultaneously(with: DragGesture(minimumDistance: 0))
.onEnded { value in
if value.first != nil, let location = value.second?.startLocation {
print("did tap location: \(location)")
}
}
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment