Iphone – touchesEnded not being called??? or randomly being called

iphonemulti-touchtouchesbeganuitouch

If I lift my finger up off the first touch, then it will recognize the next touch just fine. It's only when I hold my first touch down continuously and then try and touch a different area with a different finger at the same time. It will then incorrectly register that second touch as being from the first touch again.

Update It has something to do with touchesEnded not being called until the very LAST touch has ended (it doesn't care if you already had 5 other touches end before you finally let go of the last one… it calls them all to end once the very last touch ends)

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

 UITouch* touch = [touches anyObject];

 NSString* filename = [listOfStuff objectAtIndex:[touch view].tag];

// do something with the filename now

}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

 ITouch* touch = [touches anyObject];
 NSString* buttonPressed = [listOfStuff objectAtIndex:[touch view].tag];

 // do something with this info now
}

Best Answer

I had this today, (or rather I had this problem dumped on me today!).

What I saw happening:

  • Touch Screen With Finger 1
  • touchesBegan fires
  • Touch Screen With Finger 2
  • touchesBegan fires
  • Release Finger 2
  • nothing happens
  • Release Finger 1
  • touchesEnded fires
  • touchesEnded fires

As Gavin Clifton said, it only happens if you add a gesture recognizer. Without a recognizer added, touchesEnded fires after each finger is released. Which would be great if I didn't need to use recognizers...!!!

I solved this by adding gestureRotation.delaysTouchesEnded = FALSE; to my recognizer creation/adding code:

gestureRotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(gestureRotation_Callback:)];

[gestureRotation setDelegate:self];
gestureRotation.cancelsTouchesInView = FALSE;
gestureRotation.delaysTouchesEnded = FALSE;        // <---- this line!!
[self.view addGestureRecognizer: gestureRotation];
[gestureRotation release];

Now the gestures work, and touchesBegan no longer queues!

Related Topic