Detecting a Long Crane in a UIScrollView

How would I detect a long crane (tap and hold) in a UIScrollView?

+4
source share
2 answers

In the touchesBegan: view touchesBegan: you can invoke your long descriptor with some delay.

 [touchHandler performSelector:@selector(longTap:) withObject:nil afterDelay:1.5]; 

Then in sight touchesEnded: you can cancel this call if not enough time has passed:

 [NSObject cancelPreviousPerformRequestsWithTarget:touchHandler selector:@selector(longTap:) object:nil]; 
+9
source
 //Add gesture to a method where the view is being created. In this example long tap is added to tile (a subclass of UIView): // Add long tap for the main tiles UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longTap:)]; [tile addGestureRecognizer:longPressGesture]; [longPressGesture release]; -(void) longTap:(UILongPressGestureRecognizer *)gestureRecognizer{ NSLog(@"gestureRecognizer= %@",gestureRecognizer); if ([gestureRecognizer state] == UIGestureRecognizerStateBegan) { NSLog(@"longTap began"); } } 
+2
source

Source: https://habr.com/ru/post/1306129/


All Articles