1

a Text view is like:

Text("hello world")
.onTapGesture{
...}

can I get the tab position ,so that to infer which word is tapped.

龙方哲
  • 125
  • 1
  • 9

1 Answers1

0

Here is an approach how to get tap location in Text view coordinate space:

Text("hello world")
.gesture(DragGesture(minimumDistance: 0).onEnded { value in
    print("Position: \(value.location)") // in local coordinates
})
Asperi
  • 228,894
  • 20
  • 464
  • 690