【UIKit】-2- UIAccelerometer-加速计事件

来源:互联网 发布:mac os x系统下载 iso 编辑:程序博客网 时间:2024/06/12 00:57

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来监听加速计事件。



 

 

0 0
原创粉丝点击