使用 UIGestureRecognizer 同时识别触摸和点击手势

发布于 2024-10-22 23:36:33 字数 48 浏览 7 评论 0原文

是否可以使用 UIGestureRecognizer 同时处理触摸和点击手势识别?

Is it possible to handle Touch and Tap gestures recognition simultaneously with UIGestureRecognizer?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寻梦旅人 2024-10-29 23:36:33

我不知道你指的是哪种触摸识别器,但我想你指的是像平底锅这样的东西。但是,是的,这是可能的,只需创建多个手势识别器即可。示例:

UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTap:)];
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePan:)];
[self.view addGestureRecognizer:tapRecognizer];
[self.view addGestureRecognizer:panRecognizer];

我假设您了解手势识别器的基础知识。如果没有,我很乐意为您提供教程链接并帮助您解决任何其他问题。
但是,如果它们都使用相同类型的手势(例如平移和滑动,或者单击和双击识别器),则您将需要使用 requiresgesturerecognizertofail

I don't know what kind of recognizer you mean with touch, but i suppose you mean something like pan. But yes, it is possible, simply by creating multiple gesturecognizers. Example:

UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTap:)];
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePan:)];
[self.view addGestureRecognizer:tapRecognizer];
[self.view addGestureRecognizer:panRecognizer];

I'm assuming you know the basics of gesturerecognizers. If not, i'll be happy to give you a link to a tutorial and help you with any additional questions.
However, if they both use the same kind of gesture (like pan and swipe, or a single and double tap recognizer), you will need to use requiresgesturerecognizertofail.

橘亓 2024-10-29 23:36:33

只要将手势上的cancelsTouchesInView 设置为NO,就可以使用触摸方法和手势。

You can use touch methods and gestures as long as you set cancelsTouchesInView to NO on the gesture.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文