UICollectionView 的长按点击手势识别器 Objective-c

Long press tap gesture recogniser for UICollectionView Objective-c

我在 ViewController 中使用 UICollectionView 来显示图像,我希望用户能够通过长按删除照片,但我无法检测到长按手势。我已经阅读了之前的所有讨论并尝试在我的项目中实施它们,但是 none 对我有用。

通过以下行为您的图像视图启用用户交互

imgview.userInteractionEnabled =YES;

//这里是示例代码

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)
    {

    }

}