如何区分用户滑动和点击动作? [英] How to differentiate between user swipe and tap action?

查看:436
本文介绍了如何区分用户滑动和点击动作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,其中我有一个视图,其中包含subView。
我想跟踪滑动和点击操作,如一次单击。

I am developing a app in which I have a view which contains subView in it. I want to track both swipe and tap actions such as a single click.

只有当用户触摸我的子视图时,才应跟踪操作。

Actions should be tracked only when the user touches within my subview. When the user taps I want to perform one action, when the user swipes I want perform another.

为了跟踪滑动,我实现了 UIGestureRecognizer

For tracking the swipe, I implemented UIGestureRecognizer and it is working fine. But I don't know how to track the tap option. Please guide me how to achieve this.

主要的是,当我点击它应该调用tap操作,反之亦然。

The main thing is, when I tap it should call tap action only and vice versa.

推荐答案

您可以使用 UITapGestureRecognizer

You can use UITapGestureRecognizer for tap gestures.


UITapGestureRecognizer UIGestureRecognizer
的一个具体子类,用于查找单个或多个点击。对于手势
识别,指定的手指数必须点击视图a
指定的次数 p>

"UITapGestureRecognizer is a concrete subclass of UIGestureRecognizer that looks for single or multiple taps. For the gesture to be recognized, the specified number of fingers must tap the view a specified number of times."

此方法包括 numberOfTapsRequired (手势的点击数识别)和 numberOfTouchesRequired (点击手势识别所需的手指数)属性,您可以在其中准确设置您对用户的反应

This method includes the numberOfTapsRequired ("The number of taps for the gesture to be recognized.") and numberOfTouchesRequired ("The number of fingers required to tap for the gesture to be recognized") properties where you can set exactly how you want it to react to user action.

在这种情况下,由于您只希望在点击一次时将其激活,这两个属性的默认设置(两者都具有默认值1)应该是罚款。

In this case, as you only want it to be activated when tapped once, the default settings for both these properties (both have default values of 1) should be fine.

这篇关于如何区分用户滑动和点击动作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆