title: Why are UIViewController touchesBegan, touchesMoved & touchesEnded only being called when the first of two touches begins, moves or ends?
body: <p>I'm having an issue with handling more than one touch through the touchesBegan/Moved/Ended methods of UIViewController. I'm also seeing the same behaviour in a cocos2d app (using ccTouchesBegan/Moved/Ended) so I think this question can be applied to all touch handling in iOS. I've put the code that I'm using below, followed by the results that I'm seeing.</p>
  
  <p>All methods are implemented on a UIViewController subclass.</p>
  
  <pre><code>- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
  {
      NSLog(@"Touches Began");
      [self logTouchesFor: event];
  
      [super touchesEnded: touches withEvent: event];
  }
  
  - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
  {
      NSLog(@"Touches Moved");
      [self logTouchesFor: event];
  
      [super touchesEnded: touches withEvent: event];
  }
  
  - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
  {
      NSLog(@"Touches Ended");
      [self logTouchesFor: event];
  
      [super touchesEnded: touches withEvent: event];
  }
  
  -(void)logTouchesFor:(UIEvent *)event
  {
      int count = 1;
  
      for (UITouch *touch in event.allTouches)
      {
          CGPoint location = [touch locationInView: self.view];
  
          NSLog(@"%d: (%.0f, %.0f)", count, location.x, location.y);
          count++;
      }
  }
  </code></pre>
  
  <p>Now for the interesting results...</p>
  
  <p><strong>Single Touches Work as Expected</strong></p>
  
  <p>Let's say I touch the screen with my thumb. I see in the output window that touchesBegan has been called as expected. I move my thumb around and touchesMoved gets called. Then I lift my thumb off the screen and touchesEnded gets called. All this is as expected, I'm including it in the question as a control case - just to be clear that my view controller is receiving touch events and I haven't missed a <code>vc.view.userInteractionEnabled = YES</code> anywhere.</p>
  
  <p><strong>The Second Touch Doesn't Cause touchesBegan, touchesMoved or touchesEnded to be called</strong></p>
  
  <p>This is the most interesting one. Let's say I touch the screen with my thumb (touchesBegan is called) and hold it still on the screen. Then I touch somewhere else on the screen with my index finger, whilst keeping my thumb in the same place. TouchesBegan is not called. Then let's say I move my index finger whilst keeping my thumb absolutely still (this can be tricky but it is possible). TouchesMoved is not called. Then, I lift my index finger off the screen. TouchesEnded is not called. Finally, I move my thumb and touchesMoved is called. Then I lift my thumb from the screen and touchesEnded is called.</p>
  
  <p>Just to be clear: I've set <code>self.view.multipleTouchEnabled = YES</code> in my <code>viewDidLoad</code> method.</p>
  
  <p><strong>Information About the Second Touch is Available, Providing the First Touch Moves</strong></p>
  
  <p>This time I do something very similar to the example immediately above. I touch the screen with my thumb, then index finger whilst keeping my thumb still. TouchesBegan is called when my thumb hits the screen, but not my index finger. Now I move my thumb, and touchesMoved is called. Not only that, but there are two touches in the event.allTouches array (and yes, the second touch is where I would expect it to be). This means that the system is aware that I have touched the screen a second time, but I am not being notified through the touch handling methods on my view controller.</p>
  
  <p><strong>How Can I be Notified About Changes to the Second Touch?</strong></p>
  
  <p>I'd really like to be able to respond to changes in the location or state of the second touch as they happen, rather than when the first touch also changes. A lot of the time this won't be an issue because it's very hard to change one touch without impacting on the other, but I have at least one situation where it can be an issue. Am I missing something obvious? Has anyone else noticed this behaviour or had issues with it?</p>
  
  <p>In case it's relevant, I'm using an iPhone 3GS running iOS 5.1.</p>