We dont need a separate Swipe Gesture Recognizer. The different states in Long Press Gesture Recognizer can be used to handle this scenario.
Long Press Gesture has different states Like UIGestureRecognizerStateBegan, UIGestureRecognizerStateChanged and UIGestureRecognizerStateEnded.
UIGestureRecognizerStateBegan gets called as soon as you long press the subview.
UIGestureRecognizerStateChanged gets called when the user tries to move the finger .
UIGestureRecognizerStateEnded gets called when the user lifts the finger from the touch point.
- (void)longPressGestureForPreviewImageView:(UILongPressGestureRecognizer *)recognizer{
if (recognizer.state == UIGestureRecognizerStateBegan)
{
// Long press detected, start the timer
[self showPreviewImage:recognizer];
}
else if(recognizer.state == UIGestureRecognizerStateChanged)
{
NSLog(@"Swipe up");
if ([self.thumbnailImageView.gestureRecognizers containsObject:recognizer]) {
[self.thumbnailImageView removeGestureRecognizer:recognizer];
}
}
else if(recognizer.state == UIGestureRecognizerStateEnded)
{
[self hidePreviewImage];
}
So we can use the Gesture Delegate methods to handle the swipe along with a Long Press Gesture Recognizer.