I try to bring up a warning window when I touch and hold the image for 2 seconds. Here is what I got so far:
- (void)viewDidLoad { [super viewDidLoad]; UILongPressGestureRecognizer *tapAndHoldGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapAndHoldGesture:)]; tapAndHoldGesture.minimumPressDuration = 0.1; tapAndHoldGesture.allowableMovement = 600; [self.view addGestureRecognizer:tapAndHoldGesture]; } - (void) handleTapAndHoldGesture:(UILongPressGestureRecognizer *)gestureRecognizer{ if (gestureRecognizer.state != UIGestureRecognizerStateEnded) { return; } UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Gesture:" message:@"hold it" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; }
Not sure if this means anything, but the Image View is programmatically created later, and not at boot time. Thank you in advance for any help.
In addition, I looked at the following links:
Long gesture of clicking on a UICollectionViewCell
Long gesture recognition id in UIButton?
Apple Link 1
Apple Link 2
source share