How can I get the number of touches made in a view using the iPhone SDK?

I want to get the number of touches made in the view. If I touch the image with one finger, I want to get the score as one, and if I touch the image with two fingers, I want to get the value as two.

I am using the following code.

- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
    NSArray *allTouches = [touches allObjects];
    int count = [allTouches count];
    printf("\n the count is :%d",count);
}

Here I get the score always as 1, even when I touch with two fingers.

+3
source share
3 answers

Your problem is probably disabled. Turn it on.

yourView.multipleTouchEnabled = YES;
+4
source

@Deepak is right. Check the property for the view. Reference documents for UIResponder clearly state

. , multipleTouchEnabled YES.

+1

Why not just take int count = [touches count];from your original NSSetand do with it?

0
source

All Articles