2

I am using a UICollectionView in my ViewController for displaying images and i want that user should be able to delete photos on long press, but i am not able to detect long press gesture. I have read all the previous discussions and tried to implement them in my project also but none of them worked for me.

Developer
  • 822
  • 9
  • 23

1 Answers1

3

Enable user interaction for your imageview by below line

imgview.userInteractionEnabled =YES;

//Here is sample code

UILongPressGestureRecognizer *gestureRecognizer = [[UILongPressGestureRecognizer alloc] init];
[gestureRecognizer addTarget:self action:@selector(imgLongPressed:)];
gestureRecognizer.delegate = self;
imgview.userInteractionEnabled =YES;
[imgview addGestureRecognizer: gestureRecognizer];

- (void) imgLongPressed:(UILongPressGestureRecognizer*)sender
{
    UIImageView *view_ =(UIImageView*) sender.view;
    CGPoint point = [sender locationInView:view_.superview];

    if (sender.state == UIGestureRecognizerStateBegan)
    {

    }
    else if (sender.state == UIGestureRecognizerStateChanged)
    {

    }
    else if (sender.state == UIGestureRecognizerStateEnded)
    {

    }

}
Bhadresh Mulsaniya
  • 2,610
  • 1
  • 12
  • 25