tracking two fingers with TouchesMoved
Asked Answered
D

5

6

Suppose I have two fingers touching iPhone's screen but just one is moving.

TouchesMoved will just show one finger (event).

How do I know which of the two fingers TouchesMoved is referring too?

Decant answered 10/8, 2009 at 16:49 Comment(0)
D
1

I discovered that it is possible to do what I want. Just check Stanford's CS193P course on iTunesU.

Decant answered 10/9, 2009 at 8:53 Comment(0)
W
1

Unfortunately if you think about it there's no "definitive" way to associate one finger with one touch point. It isn't, after all, that your fingers have globally unique id's that the iPhone has the ability to sample.

What you need to do is keep a record of the "prior" locations, which is useful for managing pinches and other things anyway - and tag each finger based on the proximity to the prior touches set.

Wilder answered 10/8, 2009 at 16:56 Comment(1)
thanks, but I discovered there's a way to track fingers... alexcurylo.com/blog/2008/11/24/snippet-pinch-and-stretchDecant
D
1

I discovered that it is possible to do what I want. Just check Stanford's CS193P course on iTunesU.

Decant answered 10/9, 2009 at 8:53 Comment(0)
E
1

First, enable multitouch on your UIView:

self.multipleTouchEnabled = true

Then keep a dictionary for the UITouch objects. The same UITouch objects gets passed in touchesBegan, touchesMoved, and touchesEnded:

var touchTypes = Dictionary<UITouch, Int>()

override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
    for touchObject in touches {
        touchTypes.updateValue(i, forKey: touch as UITouch) //determine i for your own implementation
    }
}

override func touchesMoved(touches: NSSet, withEvent event: UIEvent) {
    let type = touchTypes[touch] //depending on this value, do something
}

override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {
    for touchObject in touches {
        touchTypes.removeValueForKey(touchObject as UITouch)
    }
}
Eustache answered 19/10, 2014 at 0:3 Comment(0)
L
0

You get the touches as a NSSet * from the TouchesBegan method, you'll need to loop through all the touches and put them into context of your app so that you can identify them later.

It would've been much easier to help you if you described your intent ...

Lawabiding answered 10/8, 2009 at 17:11 Comment(2)
I have an image that I want to move around. This image can be moved by one finger (one person) or two fingers (two persons). Imagine that person A moves his finger from point A1 to A2. If there is a person B, it moves his finger from point B1 to B2. If just one person is present, then the image is moved the variation between the coordinates of points A1 and A2. If two persons are moving, then the image moves the SUM of the variations of the positions of the two fingers. So, I need to track how much each finger moved.Decant
I have a similar problem and the touches set always contain single object in my case.Hyacinthia
T
0

You wrote

TouchesMoved will just show one finger (event).

but this isn't actually true: as long as two fingers are touching the screen, and at least one of them moves, you'll get a touchesMoved with both fingers.

if one finger is picked up temporarily, you may get some touchesMoved calls with just one finger, so you have to decide what to do about that.

Towboat answered 11/8, 2009 at 4:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.