Monish Kumar
Monish Kumar

Reputation: 2848

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

I want to get number of touches made on the view. If I touch the image with single finger I want to get the count as one and if I touch the image with two fingers I want to get the value as two.

I'm 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'm getting the count always as 1, even when I touch with two fingers.

Upvotes: 3

Views: 1959

Answers (3)

visakh7
visakh7

Reputation: 26390

@Deepak is right. Check the property for the view. The reference documents for UIResponder clearly states

Multiple touches are disabled by default. In order to receive multiple touch events you must set the a multipleTouchEnabled property of the corresponding view instance to YES.

Upvotes: 1

Deepak Danduprolu
Deepak Danduprolu

Reputation: 44633

Your problem is probably multitouch being disabled. Enable it.

yourView.multipleTouchEnabled = YES;

Upvotes: 4

buildsucceeded
buildsucceeded

Reputation: 4243

Why not just take int count = [touches count]; from your original NSSet and be done with it?

Upvotes: 0

Related Questions