I'm trying to call an alert box when I touch and hold down an image for 2 seconds. Here's 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 effects anything, but the Image View is programmatically created later and not on load. Thank you in advance as any help is appreciated..
Also, I've looked at the following links:
Long press gesture on UICollectionViewCell