问题描述
我一直想触摸指尖的x和y坐标。
例如,我也想在使用其他应用程序时获取坐标。所以我想在后台处理下面的代码。
每个人都知道吗?非常感谢!
import SwiftUI
struct ContentView: View {
@State private var word: String = ""
@State var xPos: CGFloat = 0
@State var yPos: CGFloat = 0
var body: some View {
ZStack{
Image(systemName: "")
.resizable()
.padding()
.gesture(DragGesture(minimumdistance: 0,coordinateSpace: .global).onChanged {
dragGesture in
self.xPos = dragGesture.location.x
self.yPos = dragGesture.location.y
print(self.xPos,self.yPos)
print(dragGesture.translation)
}
.onEnded {dragGesture in
self.xPos = dragGesture.location.x
self.yPos = dragGesture.location.y
print("Last",self.xPos,self.xPos)
print("Last",dragGesture.translation)
})
vstack{
HStack{
Text("\(xPos)")
Text("\(yPos)")
}
vstack {
TextField("please write",text: $word)
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding()
Text("\(word)")
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)