Kapil Choubisa
Kapil Choubisa

Reputation: 5232

Detect Two finger touch on UIIMageView

I am trying to detect two finger touch on a UIImageView object. In xib I had set multi-touch enbled. Then I implemented the following code:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    //NSLog(@"%@", [[touches anyObject] class]);
    UITouch* touch = [touches anyObject];
    NSLog(@"%@", [touch class]);
    if ([touches count] > 1)
        NSLog(@"multi touches: %d fingers", [touches count]);

    NSUInteger numTaps = [touch tapCount];

    if (numTaps == 1) {
        NSLog(@"single tap");
    } else {
        NSLog(@"multi tap: %d", numTaps);
    }
}

What actually happning with this code is: This is detecting multiple taps not multi-touch. How can I detect that user touched on object with two finger(Multi-Touch).

Thanks

Upvotes: 2

Views: 4925

Answers (3)

Janak Nirmal
Janak Nirmal

Reputation: 22726

You can use event object for the same as

 NSSet *touch = [event allTouches];
 int touchCounts = [touch count];
 if(touchCounts >2)
 {
 //Multitouch.
 }

Upvotes: 0

Ved
Ved

Reputation: 612

Use gestureRecognizers like this:

UITapGestureRecognizer *twoFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleFingerTap:)];
twoFingerTap.numberOfTouchesRequired = 2;
[super addGestureRecognizers:twoFingerTap];

http://developer.apple.com/library/ios/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/GestureRecognizers/GestureRecognizers.html

Upvotes: 4

At this point you are really better off using a gesture recognizer, looking for two taps with two fingers.

Upvotes: 0

Related Questions