2013-03-22 2 views
7

aggiungo singTap e doubletap ad una vista come il codice qui sotto:Implementare singleTap e doubletap in Objective-C

-(void)awakeFromNib{ 
    [self setUserInteractionEnabled:YES]; 
    // 
    UITapGestureRecognizer *doubleTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTapGesture:)]; 
    doubleTapGesture.numberOfTapsRequired = 2; 
    [self addGestureRecognizer:doubleTapGesture]; 

    UITapGestureRecognizer *singleTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTapGesture:)]; 
    singleTapGesture.numberOfTapsRequired = 1; 
    [self addGestureRecognizer:singleTapGesture]; 
} 

-(void)handleSingleTapGesture:(UITapGestureRecognizer *)singleTapGesture{ 
    [[self delegate] singleTapOnView]; 
} 

-(void)handleDoubleTapGesture:(UITapGestureRecognizer *)doubleTapGesture{ 
    [[self delegate] doubleTapOnView]; 
} 

Quando DoubleTap il singleTap anche fuoco. Come disabilitare singleTap quando doubleTap? Grazie!

risposta

11

Dite al riconoscitore single-tap che richiede il sistema di riconoscimento toccare due volte a fallire prima che innesca:

[singleTapGesture requireGestureRecognizerToFail:doubleTapGesture]; 

(Questo è in realtà l'esempio canonico nella UIGestureRecognizer docs for this method.)