0

我有一个 UITapGestureRecognizer 添加到我的 UITextView。我已将 numberOfTapsRequired 设置为 1,但我确实需要将其设为 ANY。aField 是一个 UITextView。我需要任意数量的水龙头来调用选择器。有什么办法可以做到这一点?

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(stateFieldSelected)];
singleTap.numberOfTapsRequired = 1;
[aField addGestureRecognizer:singleTap];

目的是,当他们点击状态字段时,我会启动一个 UIPickerView,但如果他们双击或三次点击状态字段,它将拉起键盘。我可以添加许多手势识别器,但必须这样做似乎很蹩脚。

4

1 回答 1

2

在视图上使用多个手势识别器没有任何问题。但是,如果您担心除了双击操作之外还会调用两次单击操作,您可以指定单击识别器需要双击识别器失败:

UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(someOtherMethod)];
[doubleTap setNumberOfTapsRequired:2];
[aField addGestureRecognizer:doubleTap];

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(stateFieldSelected)];
[singleTap setNumberOfTapsRequired:1];
[singleTap requireGestureRecognizerToFail:doubleTap];
[aField addGestureRecognizer:singleTap]; 
于 2012-11-19T22:37:46.840 回答