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

标签 ios uicollectionview uilongpressgesturerecogni

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

最佳答案

通过下面的行为您的 ImageView 启用用户交互

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

    }

}

关于ios - UICollectionView Objective-c 的长按点击手势识别器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38242680/

相关文章:

iphone - IOS JSON 从 "JSON Dict"获取所有值

c# - iOS 7 不断在空字典上发送 IDLE 命令

Swift UICollectionView 文本字段

ios - 如何在 UICollectionView performBatchUpdates block 中对移动、插入、删除和更新进行排序?

objective-c - 将 UILongPressGestureRecognizer 与 UIPanGestureRecognizer 相结合

ios - 为 iOS 设置 XMPPFramework

ios - UICollectionView:删除单元格问题

ios - 需要应用 UIRotationGestureRecognizer 后跟 UILongPressGestureRecongnizer

ios - 在表格 View 自定义单元格中的图像上长按手势

ios - 为什么这行不通? ( SpriteKit 相关)