检查用户是否没有触摸屏幕

发布于 2024-10-21 13:30:34 字数 194 浏览 5 评论 0原文

我必须检查用户是否触摸了屏幕。如果应用程序空闲一段时间,则执行一些任务。
我知道如何使用 TouchBegin 和 touchEnd 方法,但我的项目很大,有些对象没有响应这些方法。

目前,我在与对象的每次交互中都使用计时器,我知道这是非常糟糕的方式,并且必须有一些好的方法来做到这一点......

任何人都可以提出更好的解决方案吗?

I have to check if user did touch the screen.And perform some task if the application was idle for a time duration.
I know that how to use the TouchBegin and touchEnd method but my project is large and some objects are not responding to these methods.

Currently i am using timer in each and every interaction with the objects i know this is very bad way and there must be some good way to do this...

Can anyone suggest a better solution ?

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

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

发布评论

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

评论(3

好听的两个字的网名 2024-10-28 13:30:34

记录最后一次 TouchUp 事件发生的时间。然后您可以检查这一情况,而无需任何计时器。

Record the time that the last TouchUp event happened. You can then check that without the need for any timers.

黑寡妇 2024-10-28 13:30:34

您需要一个全局计时器,该计时器会在每次触摸结束事件时取消并重新启动。

You want one global timer which is cancelled and restarted on each touch end event.

意犹 2024-10-28 13:30:34

为什么你说某些对象没有响应 TouchBegin 和 touchEnd 方法。没有这些方法,你如何检测用户是否触摸过。我不认为在这种情况下使用计时器是正确的方法。所以让这些方法对象响应这些方法。

尝试创建一个布尔变量,例如:- BOOL isTouched

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

      isTouched =  Yes;
}

现在根据这个布尔变量创建条件
祝你好运!

Why you are saying that some objects are not responding to TouchBegin and touchEnd methods.Without these methods how can you detect that the user had touched or not.i do not think that using timer in this situation will be a correct way .So make those objets to respond to these methods .

Try making a bool variable eg:- BOOL isTouched

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

      isTouched =  Yes;
}

Now make you conditions according to this bool variable
Good Luck!

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