UIImageView 无法在自定义的可滑动 UITableViewCell 中检测长按手势,该 UITableViewCell 是一个滚动视图 [英] UIImageView can't detect long press gesture in a customized swippable UITableViewCell which is a scrollview

查看:19
本文介绍了UIImageView 无法在自定义的可滑动 UITableViewCell 中检测长按手势,该 UITableViewCell 是一个滚动视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用可滑动的 UITableViewCell 子类,链接如下:

I'm using the swippable UITableViewCell subclass as linked below:

https://github.com/CEWendel/SWTableViewCell

在我的单元格中,有一个 UIImageView.我在 UIImageView 中添加了一个 UILongPressGestureRecognizer.当 UIImageView 被长按时,我想制作一个Wiggle-Jiggle"效果.但是每次我长按 UIImageView 时,都会选择整个单元格.所以我深入研究了可滑动的 UITableViewCell 代码.我发现单元格本身也设置了一个 UILongPressGestureRecognizer 如下:

In my cell, there's a UIImageView. I added a UILongPressGestureRecognizer to the UIImageView. I want to make a 'Wiggle-Jiggle' effect when the UIImageView was long pressed. But every time I long pressed the UIImageView, the whole cell was selected. So I dived into the swippable UITableViewCell code. I found that the cell itself was also set a UILongPressGestureRecognizer as following:

    self.longPressGestureRecognizer = [[SWLongPressGestureRecognizer alloc] initWithTarget:self action:@selector(scrollViewPressed:)];
    self.longPressGestureRecognizer.cancelsTouchesInView = NO;
    self.longPressGestureRecognizer.minimumPressDuration = kLongPressMinimumDuration;
    self.longPressGestureRecognizer.delegate = self;
    [self.cellScrollView addGestureRecognizer:self.longPressGestureRecognizer];

代码来自 SWTableViewCell.m,你可以从上面的链接找到.

The code is from SWTableViewCell.m which you can find from the above link.

现在我想知道有没有办法将 UILongPressGestureRecognizer 锁定到单元格并在 UIImageView 时触发 UIImageView 的动作被长按?

Now I want to know is there a way to lock the UILongPressGestureRecognizer to the cell and trigger the action for the UIImageView when the UIImageView was long pressed?

非常感谢大家的帮助.

推荐答案

终于找到原因了.我把它贴在这里只是以防万一其他人在未来遇到同样的困惑.

Finally I found the reason. I posted it here just incase anybody else meet the same confusion in the future.

我使用的库,有几行代码来设置longPressGestureRecognizer.

I the library I used, there is several lines code to set the longPressGestureRecognizer.

self.longPressGestureRecognizer = [[SWLongPressGestureRecognizer alloc] initWithTarget:self action:@selector(scrollViewPressed:)];
    self.longPressGestureRecognizer.cancelsTouchesInView = NO;
    self.longPressGestureRecognizer.minimumPressDuration = kLongPressMinimumDuration;
    self.longPressGestureRecognizer.delegate = self;
    [self.cellScrollView addGestureRecognizer:self.longPressGestureRecognizer];

有一行:self.longPressGestureRecognizer.minimumPressDuration = kLongPressMinimumDuration;#define kLongPressMinimumDuration 0.16f.所以我的问题的原因是持续时间 0.16f 太小了.它会比我的长按更早触发.如果我更改持续时间,例如将其更改为 0.5 秒,则一切正常.

There's one line: self.longPressGestureRecognizer.minimumPressDuration = kLongPressMinimumDuration; and the #define kLongPressMinimumDuration 0.16f. So the reason of my issue is the duration 0.16f is too small. It'll be triggered earlier than my long press. If I change the duration, like change it to 0.5s, everything is fine.

这篇关于UIImageView 无法在自定义的可滑动 UITableViewCell 中检测长按手势,该 UITableViewCell 是一个滚动视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆