user856232
user856232

Reputation: 1113

Multitouch in MonoTouch on iOS

I need to track multiple touch events in an iOS MonoTouch application. I have overridden the TouchesBegan, TouchesCancelled, TouchesMoved and TouchesEnded methods.

What I need to figure out now is how to iterate through the touches (there will be more than one) during each of those overrides and match them up. I want to know when a touch begins and do something with it versus a different touch event. The user may put a finger down at which time I will start a timer to do something if that finger stays down.

If during that time the user puts down another finger I will want to start a timer for that one that is different than the first one.

I am pretty sure I can figure out a way to store my timers and such. What I can't figure out it how to iterate through the touch events that the NSSet contains in each of the overrides and then how to uniquely identify them BETWEEN the overrides.

I am assuming that a TouchesBegan touch in the NSSet will match up with a TouchesMoved, TouchesCancelled or TouchesEnded touch in the NSSets that those overrides get as well.

Is that true? If so how to I get at each one and uniquely ID them to match them up?

Upvotes: 2

Views: 879

Answers (1)

jonathanpeppers
jonathanpeppers

Reputation: 26485

Here is a good example of MonoGame's use of TouchesBegan etc: https://github.com/mono/MonoGame/blob/develop/MonoGame.Framework/iOS/iOSGameView_Touch.cs

UITouch also has a timestamp field you could use to differentiate touches. I think you should store them in a dictionary to get the functionality you mention.

Here is the class reference for UITouch: http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UITouch_Class/Reference/Reference.html

Upvotes: 4

Related Questions