[英]how to detect if phone has been moved
我想知道如何使用 swift 檢測 iPhone 在過去 60 秒內是否移動過
我在下面遇到了這個代碼,但只有在手機晃動時才有效。
是否可以檢測到手機何時被移動但不會劇烈晃動?
override func motionEnded(motion: UIEventSubtype,
withEvent event: UIEvent?) {
if motion == .MotionShake {
let controller = UIAlertController(title: "Shake",
message: "The device is shaken",
preferredStyle: .Alert)
controller.addAction(UIAlertAction(title: "OK",
style: .Default,
handler: nil))
presentViewController(controller, animated: true, completion: nil)
}
}
我認為您將需要使用加速度計並對輸出應用適度的低通濾波器,這樣您就可以忽略非常平緩的變化,但會獲得適度的加速度。 您應該能夠調整閾值。
我建議搜索“ios加速計低通濾波器”。 您將需要編寫自己的代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.