Hey all,
I have been using touches began to track as many as 8 touches, and each triggers an event. These touches can occur at the same time, or staggered.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"Touch Began");
NSSet *allTouches = [event allTouches];
for (int i=0; i<allTouches.count; i++) {
UITouch *touch = [[allTouches allObjects] objectAtIndex:i];
if (/*touch inside button in question*/) {
//Trigger the event.
}
}
}
That code works for the multitouch, and it has no problems, EXCEPT: (See if you can guess)
Due to the way allTouches works, it literally gets all of the touches. Because of this, it loops through all of the touches that are currently active when the user starts another touch, and thus triggers the event of one of the buttons twice.
Ex: Johnny is pressing button 1. Event 1 occurs. Johnny leaves his finger on button 1, and presses button 2. Event 2 occurs, BUT button 1 is still a part of allTouches, and so, event 1 is triggered again.
So here's the question: How do I get the new touch?