gpt4 book ai didi

iphone - 如何使用 UITapGestureRecognizer 同时检测点击和双击?

转载 作者:技术小花猫 更新时间:2023-10-29 10:18:47 27 4
gpt4 key购买 nike

例如,我有一个 View ,我想要两种不同的手势:

点击执行操作 A。双击以执行操作 B。

问题出在 UITapGestureRecognizer 上,我只能设置所需的最小点击次数。在双击手势识别器识别双击之前,单击手势识别器识别点击。

例子:

_tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureRecognized:)];
_tapGestureRecognizer.numberOfTouchesRequired = 1;
_tapGestureRecognizer.numberOfTapsRequired = 1;
[self addGestureRecognizer:_tapGestureRecognizer];

_doubleTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTapGestureRecognized:)];
_doubleTapGestureRecognizer.numberOfTouchesRequired = 1;
_doubleTapGestureRecognizer.numberOfTapsRequired = 2;
[self addGestureRecognizer:_doubleTapGestureRecognizer];

即使我快速双击,它也总是能识别出单击。我如何设置它以便点按手势识别器等待并查看双击手势识别器是否识别?

最佳答案

这是我在我的一个旧项目中使用的,我希望它能帮助你。

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

UITapGestureRecognizer *doubleTap = [[[UITapGestureRecognizer alloc] initWithTarget: self action:@selector(doDoubleTap)] autorelease];
doubleTap.numberOfTapsRequired = 2;
[self.view addGestureRecognizer:doubleTap];

[singleTap requireGestureRecognizerToFail:doubleTap];

关于iphone - 如何使用 UITapGestureRecognizer 同时检测点击和双击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19127501/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com