1.官方文档介绍(加速计事件)
The UIAccelerometer classlets you register to receive acceleration-related data from the onboardhardware. As a device moves, its hardware reports linear acceleration changesalong the primary axes in three-dimensional space. You can use this data todetect both the current orientation of the device (relative to the ground) andany instantaneous changes to that orientation. You might use instantaneouschanges as input to a game or to initiate some action in your application.
You do not createaccelerometer objects directly. Instead, you use the shared UIAccelerometer objectto specify the interval at which you want to receive events and then set itsdelegate property.Upon assigning your delegate object, the accelerometer object begins deliveringacceleration events to your delegate immediately at the specified interval.Events are always delivered on the main thread of your application.
The maximumfrequency for accelerometer updates is based on the available hardware. You canrequest updates less frequently but cannot request them more frequently thanthe hardware maximum. Once you assign your delegate, however, updates aredelivered regularly at the frequency you requested, whether or not theacceleration data actually changed. Your delegate is responsible for filteringout any unwanted updates and for ensuring that the amount of change issignificant enough to warrant taking action.
For moreinformation about the data delivered to your observer, see UIAcceleration Class Reference. Forinformation about implementing your delegate object, see
该UIAccelerometer类,可以注册从板载硬件加速接收相关数据。作为设备移动时,其硬件报告沿在三维空间中的主轴的线性加速度的变化。可以使用此数据,以检测所述设备(相对于地面)和任何瞬间变化至该方向的两个当前方向。您可以使用瞬间变化为输入到游戏或启动应用程序中的一些行动。你不直接创建对象的加速度。相反,您使用的UIAccelerometer对象指定您希望接收事件,然后设置其属性代表的时间间隔。一旦您指定委托对象,加速计对象开始在指定的时间间隔立即交付加速事件的委托。事件总是交付应用程序的主线程上。的最大频率的加速度计的更新是根据可用的硬件。你可以不经常更新的要求,但不能要求他们更频繁地比硬件最大。一旦你分配你的代表,但是,更新定期在您要求的频率交付,加速数据是否真正改变。您的代理负责过滤掉任何不想要的更新,并确保变化量是足够显著以保证采取行动。有关发送到您的观测数据的详细信息,请参阅UIAcceleration类参考。
"UIAccelerometer has been replaced by the CoreMotion framework"
1、iOS5.0以前,可以使用UIAcceleration来监听加速计事件。
2、Bug iOS5.0以后,UIAccelerometerDelegate已经被depreacated,
3、针对iOS4.0以上版本,推荐使用CMMotionManager来监听加速计事件。