ios - Detect only double or single tap with UIViews? -
i want detect double / single tap when user touches view.
i made this:
- (void)touchesbegan:(nsset *)touches withevent:(uievent *)event { uitouch *touch = [touches anyobject]; cgpoint prevloc = [touch ] if(touch.tapcount == 2) nslog(@"tapcount 2"); else if(touch.tapcount == 1) nslog(@"tapcount 1"); }
but detect 1 tap before 2 taps. how can detect 1 / 2 tap?
thanks help. found way that:
-(void)handlesingletap { nslog(@"tapcount 1"); } -(void)handledoubletap { nslog(@"tapcount 2"); } - (void)touchesended:(nsset *)touches withevent:(uievent *)event { nsuinteger numtaps = [[touches anyobject] tapcount]; float delay = 0.2; if (numtaps < 2) { [self performselector:@selector(handlesingletap) withobject:nil afterdelay:delay ]; [self.nextresponder touchesended:touches withevent:event]; } else if(numtaps == 2) { [nsobject cancelpreviousperformrequestswithtarget:self]; [self performselector:@selector(handledoubletap) withobject:nil afterdelay:delay ]; } }
Comments
Post a Comment