How do I detect user inactivity in Swift? [duplicate]

南楼画角 提交于 2019-12-14 03:38:08

问题


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).

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

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


回答1:


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


  }

}

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



来源:https://stackoverflow.com/questions/27621049/how-do-i-detect-user-inactivity-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!