如何解决swiftUI我想在后台处理我的应用程序后台处理
我一直想触摸指尖的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 举报,一经查实,本站将立刻删除。