加速计

// 1.创建加速计对象

    UIAccelerometer *accelerometer = [UIAccelerometer sharedAccelerometer];

    // 2.设置代理

    accelerometer.delegate = self;

    // 3.设置采样时间

    accelerometer.updateInterval = 1.0/60;

    //实现代理方法

#pragma mark - UIAccelerometerDelegate

- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration

{

NSLog(@"x = %.1f, y = %.1f z = %.1f", acceleration.x , acceleration.y , acceleration.z);

    // 获取加速度

    /*

     Vt = V0 + a * t (最终速度 = 初始速度 + 加速度 * 时间)

     Vt = V0 + g * t (加速度是恒定的9.8)

     Vt = V0 + g1 + g2 + g3 … (时间和加速度都是恒定的)

     Vt = V0 + a1 + a2 + a3 … (手机中时间是恒定的, 加速度不是恒定的)

     */

}

3、手机摇动事件

- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event

{

    // 判断摇晃事件类型

    if (motion == UIEventSubtypeMotionShake) {

        NSLog(@"摇一摇");

    }

}

原文地址:https://www.cnblogs.com/bluceZ/p/4629670.html