Wednesday 20 July 2011

Avoiding single tap action before performing double tap action

Hi,
Most of the time there are requirement when we have to perform some action on single tap and other independent action on double tap.
The problem that occurs is when we double tap,single tap method is always called.
There are some situations in which we do not want the single tap action get performed when doing double tap.

In touches ended method write:-

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{

NSSet *allTouches=[event allTouches];
switch ([allTouches count]) {
case 1:
{
UITouch *touch=[[allTouches allObjects]objectAtIndex:0];
switch ([touch tapCount])
{
case 1:
NSLog(@"single touch");
[self performSelector:@selector(singletap) withObject:nil afterDelay:0.3];
break;

case 2:

[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(singletap) object:nil];
NSLog(@"double touch");
break;
}
break;
}
break;
}


Happy coding:)
 

No comments:

Post a Comment