我正在寻找一种方法来检测用户是否在屏幕上(屏幕持续1秒)我尝试使用计时器,但我没有工作。这是我现在的代码。Swift 2.0如何检测用户是否持有,而不是仅仅点击
var brakeTimer = NSTimer()
func update() {
print("The user is holding the screen")
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
var brakeTimer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: "update", userInfo: nil, repeats: true)
}
override func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?) {
brakeTimer.invalidate()
}
我认为你正在寻找一个[UILongPressGestureRecognizer(https://developer.apple.com/library/ios/documentation/UIKit/Reference/UILongPressGestureRecognizer_Class/) – Cristik