UILongPressGestureRecognizer无法正常工作,但将其换成UITapGestureRecognizer工作正常。为什么? [英] UILongPressGestureRecognizer not working, but swapping it for a UITapGestureRecognizer works fine. Why?

查看:92
本文介绍了UILongPressGestureRecognizer无法正常工作,但将其换成UITapGestureRecognizer工作正常。为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UIImageView 附加了 UILongPressGestureRecognizer 附件,无论我怎么样,似乎都无法检测到长按手势配置手势识别器。但是,如果我换掉 UITapGestureRecognizer ,那么 就可以了。可能会发生什么?

I have a UIImageView with a UILongPressGestureRecognizer attached that never seems to detect a long press gesture no matter how I configure the gesture recognizer. However, if I swap it out for a UITapGestureRecognizer, that works just fine. What could possibly be going on?

这就是我配置 UILongPressGestureRecognizer 的方式:

UIImageView* cellView = (UIImageView*)[view viewWithTag:5];
UILongPressGestureRecognizer* longPressGestureRec =
    [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(cellLongPress:)];
longPressGestureRec.numberOfTapsRequired = 1;
longPressGestureRec.numberOfTouchesRequired = 1;
longPressGestureRec.minimumPressDuration = 0.4;
[cellView addGestureRecognizer:longPressGestureRec];
[longPressGestureRec release];

这是 cellLongPress 的样子:

-(void)cellLongPress:(UILongPressGestureRecognizer*)recognizer
{
    // This never gets called.
    NSLog(@"someone long pressed me");
}

非常简单,对吧?但是到目前为止没有运气让它运转起来。有什么想法吗?

Pretty straightforward, right? No luck so far getting it to work, though. Any ideas?

推荐答案

numberOfTapsRequired 设置为 1 这意味着用户必须在开始长按之前点击(手指向下,手指向上,手指向下0.4秒,手势识别)。

The numberOfTapsRequired is set to 1 which means the user has to tap once before starting the long press (finger down, finger up, finger down for 0.4 seconds, gesture recognized).

numberOfTapsRequired 更改为 0 (这是默认值)。

Change numberOfTapsRequired to 0 (which is the default).

对于该属性,文档只是说:

For that property, the documentation just says:


该数字手势为
识别所需的视图上的点按。

The number of taps on the view required for the gesture to be recognized.

但是在 UILongPressGestureRecognizer.h ,它说:


按下手势之前所需的全部水龙头数量
认可

The number of full taps required before the press for gesture to be recognized

这篇关于UILongPressGestureRecognizer无法正常工作,但将其换成UITapGestureRecognizer工作正常。为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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