tags:

views:

40

answers:

2

Hi All,

How can I detect double tap in UIScrollview?

I tried:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ 
    UITouch *touch = [touches anyObject];

    if (touch.tapCount == 2) {
        // some operations here
    }
}   

But this is not detecting double tap in UIScrollView, is there any other way to detect double tap?

Regards

+1  A: 
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    NSUInteger numTaps = [[touches anyObject] tapCount];
    if (numTaps== 2) {
         //some operations here
    }
}

Use this Code

Gyani
Thanks Gyani for replying, but scrollview is not detecting any touch event....is there other way to detect double tab in scrollview?
shishir.bobby
u may get some help from http://iphonedevelopertips.com/user-interface/detect-single-tap-in-uiscrollview.html
Gyani
+1  A: 

If you're targeting 3.2+ you could try using a UITapGestureRecognizer

UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTarget:yourViewController action:@selector(tapGesture:)];
tap.numberOfTapsRequired = 2;
tap.numberOfTouchesRequired = 1;
[scrollView addGestureRecognizer:tap];
[tap release];

Then you handle the tap in your viewcontroller:

- (void)tapGesture:(UIGestureRecognizer*)gesture {
    // Do something
}
aegzorz
thanks aegzorz,will try ur snippet...
shishir.bobby