2012-04-17 7 views
6

voglio aggiungere al mio UIViewController:Due UITapGestureRecognizer in su UIView

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)]; 
tapGesture.numberOfTapsRequired = 2; 
[self.view addGestureRecognizer:tapGesture]; 
[tapGesture release]; 

UITapGestureRecognizer *tapGesture2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture2:)]; 
tapGesture2.numberOfTapsRequired = 1; 
[self.view addGestureRecognizer:tapGesture2]; 
[tapGesture2 release]; 

il problema è se il rubinetto utente due volte i due metodi sono chiamati, e voglio che se l'utente fa doppio tap solo il primo (handleTapGesture) verrà chiamato e se poteva fare un solo tocco si chiamerà solo la seconda (handleTapGesture2)

risposta

10

uso questo ..

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture)]; 
tapGesture.numberOfTapsRequired = 2; 
[self.view addGestureRecognizer:tapGesture]; 
[tapGesture release]; 

UITapGestureRecognizer *tapGesture2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture2)]; 
tapGesture2.numberOfTapsRequired = 1; 

[tapGesture2 requireGestureRecognizerToFail: tapGesture]; 

[self.view addGestureRecognizer:tapGesture2]; 
[tapGesture2 release]; 
+0

thx per l'aiuto, ho un altro problema che ho pulsanti sul UIViewController e quando uso il codice i tasti di chiamata di questo metodo invece al metodo tasto, qualche idea del perché ? – MTA

+0

uso questo delegato - (BOOL) gestureRecognizer: (UITapGestureRecognizer *) gestureRecognizer shouldReceiveTouch: (UITouch *) tocco { \t if ((touch.view == YourButton)) { ritorno NO; } ritorno SÌ; } – userar

+0

hai controllato questo codice ?? – userar

1

è possibile utilizzare il codice che ho postato su here in questo metodo requireGestureRecognizerToFail: viene utilizzato in viewcontroller.m questo risolverà il vostro problema

Problemi correlati