swiftUI I want to process my app in the background (background proccessing)

104 views Asked by At

I always want to get the x and y coordinate touched of my fingertip.

For example, I also want to get the coordinates when using another app. So I want to process the code below in the background.

It seems good to use background processing in background mode, but I'm not sure

Did everyone any idea? Many thanks!

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

There are 0 answers