检测物体的握持情况 - iPhone Objective C

发布于 2024-09-30 01:41:17 字数 55 浏览 0 评论 0原文

如何检测用户是否将手指按住屏幕上的对象 1 秒钟?

谢谢,

马丁

How can I detect if a user holds their finger down on an onscreen object for 1 second ?

Thanks,

Martin

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

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

发布评论

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

评论(2

薆情海 2024-10-07 01:41:17

您至少需要一个状态变量和一个计时器。

在目标区域内着陆时,将状态变量设置为当前时间并启动 1 秒计时器。在目标区域外的任何触摸移动或触摸事件发生时,清除状态变量。 1 秒计时器关闭后,检查状态变量。如果它仍然有 1 秒前或更长的时间(因此尚未被清除或更改),则触摸已在目标上至少 1 秒。

You need at least one state variable and a timer.

On a touch down inside inside the target area, set the state variable with the current time and start a 1 second timer. On any touch move outside the target area or touch up event, clear the state variable. After the 1 second timer has gone off, check the state variable. If it still has a time from 1 second ago or more (and thus hasn't been cleared or changed), then the touch has been on target for at least 1 second.

暗地喜欢 2024-10-07 01:41:17

看一下 UITouch 类的时间戳属性

timestamp 触摸的时间
发生或最后一次突变的时间。
(只读)

@property(非原子,只读)
NSTimeInterval时间戳讨论
该房产的价值是
自系统启动以来的时间(以秒为单位)
触摸要么是起源于,要么是
最后改变。您可以存储和
比较这个的初始值
属性到后续时间戳
UITouch 实例的值
确定触摸的持续时间
并且,如果正在刷卡,速度
的运动。对于 的定义
自启动以来的时间值,请参阅
systemUptime 方法的描述
NSProcessInfo 类的。

使用它

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;

您应该根据您的目标操作系统在 UIResponder 或 UIGestureRecognizer 类中

Have a look at the timestamp property of UITouch Class

timestamp The time when the touch
occurred or when it was last mutated.
(read-only)

@property(nonatomic, readonly)
NSTimeInterval timestamp Discussion
The value of this property is the
time, in seconds, since system startup
the touch either originated or was
last changed. You can store and
compare the initial value of this
attribute to subsequent timestamp
values of the UITouch instance to
determine the duration of the touch
and, if it is being swiped, the speed
of movement. For a definition of the
time-since-boot value, see the
description of the systemUptime method
of the NSProcessInfo class.

You should use it with

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;

in UIResponder or UIGestureRecognizer classes according to your target OS

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