【问题标题】:Long press tap gesture recogniser for UICollectionView Objective-cUICollectionView Objective-c的长按点击手势识别器
【发布时间】:2016-07-07 10:02:38
【问题描述】:

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

【问题讨论】:

  • 您是否启用了对 imageview 的触摸。
  • @BhadreshMulsaniya 不,我没有为 imageview 启用触摸
  • 启用后工作与否?

标签: ios uicollectionview uilongpressgesturerecogni


【解决方案1】:

通过以下行为您的 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)
    {

    }

}

【讨论】:

  • @CodeGuru 欢迎 :-)
  • 你知道如何让用户重新排列 UICollectionVIew 单元格吗?
  • @CodeGuru 其实我没试过但是github上有一些demo。
猜你喜欢
  • 1970-01-01
  • 2021-09-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-13
  • 1970-01-01
相关资源
最近更新 更多