问题
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