4
votes

So, I'm capturing multiple touches and determining the number and where each of the touches occurred and I'm seeing different behavior between a UIView UIViewController.

Basically, the event handler is coded below: (in this case the touchesEnded, but it really doesn't matter). What happens in the View, is that I get the entire collection of touches, but in the controller, I get only one touch at a time, that is there is never a collection of touches, but the TouchesEnded gets executed for each touch that occurred in the same moment.

I add the subviews as identically as possible... Can someone 'spain to me what's going on? Why doesn't the controller version give me the collection?

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{ 
    int total = 0;

    for (UITouch *touch in touches) 
    {
        for(UIView *myView in [contentView subviews])
        {
            if (CGRectContainsPoint([myView frame], [touch locationInView:self.view]))
                total++;  // this is always 1 for the UIViewController
            // but I get the full number within the UIView version
        }
    }
}
2

2 Answers

0
votes

I suspect you are getting the touches but that the views are different. Check that contentView is the same and has the same subviews.

0
votes

I am not sure that I am right but this thing always work for me.

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{ 
          UITouch *touch = [touches anyObject];
         If(touch.view==your view)
         {
                NSLog("do your task here");
         }
}