如何在Swift中检测用户不活动? [英] How do I detect user inactivity in Swift?

查看:106
本文介绍了如何在Swift中检测用户不活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要实现一个空闲超时功能.为此,我只需要知道如何检测用户何时触摸屏幕(类似于Android中使用的onUserInteraction方法)即可.

I need to implement an Idle Time Out feature. To do that I simply need to know how to detect when the user touches the screen (something similar to onUserInteraction method used in Android).

那么我如何才能简单地发现用户何时与ViewController进行交互?

So how can I simply discover when the user interacts with the ViewController?

P.S:如果我问这是因为您在互联网上找不到任何好东西!

P.S: if I ask this it is because you can't find nothing good in the internet!

推荐答案

我的观点是,当用户触摸屏幕时,您需要捕获事件.方法:touchesBegan:withEvent

My take is that you need to catch the event when user touches a screen. Method: touchesBegan:withEvent

override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {

  for touch in touches {

  // get the time measurement
  // compare it to previous one for time difference


  }

}

Arthur Knopper在这里提供了一个教程,您可能会发现它很有用: http ://www.ioscreator.com/tutorials/drawing-circles-uitouch-ios8-swift

Here, Arthur Knopper has a tutorial, you may find useful: http://www.ioscreator.com/tutorials/drawing-circles-uitouch-ios8-swift

这篇关于如何在Swift中检测用户不活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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