我怎么知道 iPhone 正在移动?
有什么办法可以找到iPhone的动静吗?我需要知道 iPhone 是否仍然静止,即它没有移动,然后执行某些操作,否则如果 iPhone 正在移动(垂直或水平方向),则执行一些逻辑。
我需要阅读加速度计 didAccelerate 方法吗?或者还有其他方法,例如读取当前位置(纬度/日志)值。
[我没有 3GS]
请建议哪种是读取 iPhone 运动的最佳且可靠的方法以及如何知道 iPhone 是否静止。
谢谢
Is there any way to find, iPhone movement?. I need to know if iPhone is still i.e its not moving then do some thing or else if iPhone is moving(in vertical or horizontal direction) do some logic.
Do I need to read accelerometer didAccelerate method. Or there is some other way like reading current location (lat/log) values.
[I DON'T have 3GS]
Please suggest which is the best and robust way to read iPhone movement and how to know if iPhone is still.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您需要使用 UIAccelerometer 类。设置委托并对加速度计进行一些计算:didAccelerate 委托消息。
诀窍在于您需要设置一些阈值。如果 x、y 和 z 轴范围内没有 sig 移动,则设备不会移动。
当然,轻微的振动会导致值发生变化,这就是为什么您需要确定什么不移动才适合您的目的。
Yes, you will need to use the UIAccelerometer class. Set the delegate and do some calculations on the accelerometer:didAccelerate delegate message.
The trick is that you will want to set up some threshold values. If there is no sig movement within your range in the x, y, and z axis, the device is not moving.
Of course, slight vibrations will cause value changes, which is why you will need to determine what not moving is for your purposes.