UILongPressGestureRecognizer

UILongPressGestureRecognizer

本文介绍了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:

但是在 UILongPressGestureRecognizer.h ,它说:

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

09-17 04:08