can I get the tap position over a Text View?

只愿长相守 提交于 2021-01-28 05:30:33

问题


a Text view is like:

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

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


回答1:


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
})


来源:https://stackoverflow.com/questions/62152160/can-i-get-the-tap-position-over-a-text-view

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!