我正在嘗試確定用戶觸摸屏幕的確切時間。 我想出了這個(我的ViewController內):確定兩次觸摸之間的確切時間
var startTime: Date?
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
startTime = Date()
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
let endTime = Date()
print(endTime.timeIntervalSince(startTime!))
}
似乎工作得很好。
這是否如此精確? 有沒有辦法測試這是多麼精確?
首先,你的標題是有點混亂。請調整!那麼,要測試它,你要麼嘗試衡量時間。否則或者你需要有第二種方法可以做到這一點。但正如我所看到的那樣,當你想從觸摸的開始到結束測量總體時間時,這應該是最好的方式。但是不是使用'Date',你怎麼看待[UITouch的時間戳](https://developer.apple.com/documentation/uikit/uitouch/1618144-timestamp)? –