我在UITextView中添加了UITapGestureRecognizer。我已将numberOfTapsRequired设置为1,但我确实需要将其设置为ANY。 aField是一个UITextView。我需要任意数量的水龙头来调用选择器。有什么办法吗?
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(stateFieldSelected)];
singleTap.numberOfTapsRequired = 1;
[aField addGestureRecognizer:singleTap];
目的是,我在点击State字段时启动UIPickerView,但是如果他们双击或三次点击状态字段,它将拉起键盘。我可以添加许多手势识别器,但是这样做似乎很蹩脚。
答案 0 :(得分: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];