【发布时间】:2019-05-24 09:24:34
【问题描述】:
手机快速抖动时如何计算时间? 想要获取时间测量手机晃动的时间。
var timer = Timer()
var timeLeft = 0
override func motionBegan(_ motion: UIEvent.EventSubtype, with event: UIEvent?) {
if(motion == .motionShake){
timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(onTimerFires), userInfo: nil, repeats: true)
}
}
override func motionEnded(_ motion: UIEvent.EventSubtype, with event: UIEvent?) {
if(motion != .motionShake){
print("MotionEnded")
timer.invalidate()
}
}
计时器无休止地工作。摇停时如何停止定时器...
【问题讨论】: