我可以在文本视图上获得点击位置吗? [英] can I get the tap position over a Text View?

查看:22
本文介绍了我可以在文本视图上获得点击位置吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文本视图就像:

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

我可以获取制表符位置,以便推断点击了哪个单词.

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

推荐答案

这里是一种如何在 Text 视图坐标空间中获取点击位置的方法:

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

这篇关于我可以在文本视图上获得点击位置吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆