1

a Text view is like:

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

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

龙方哲
  • 65
  • 7

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
  • 173,274
  • 14
  • 284
  • 455