0

We're developing an application that calculates the distance between multiple finger touches. so the method 'touchesBegan' gets the coordination of these touches points.

the problem is that when I enable the multitouch property, the method must receive the touches simultaneously or it won't work if some delay happens between your two fingers means that there's a possibility of missing one or more touches. We need a way to detect all the points before calculating the distance.

this is part of the code

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    var loc1X:CGFloat?
    var loc1Y:CGFloat?
    var loc2X:CGFloat?
    var loc2Y:CGFloat?
    var locations = [CGPoint]()



    if touches.count == 2{
        // errorLabel.text = " "
        for touch in touches {

            locations.append(touch.location(in: self.view))
        }
        loc1X=locations[0].x
        loc1Y=locations[0].y
        loc2X=locations[1].x
        loc2Y=locations[1].y
        distance1 = sqrt(pow((loc2X! - loc1X!), 2) + pow((loc2Y! - loc1Y!), 2))
        print(distance1)

Thanks

Maram
  • 9
  • 3

0 Answers0