UIImageView 无法在自定义的可滑动 UITableViewCell 中检测长按手势,该 UITableViewCell 是一个滚动视图

编程入门 行业动态 更新时间:2024-10-28 03:23:36
本文介绍了UIImageView 无法在自定义的可滑动 UITableViewCell 中检测长按手势,该 UITableViewCell 是一个滚动视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

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

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

https://github/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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-29 04:21:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1183972.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:是一个   自定义   视图   手势   UIImageView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!