首页 > 其他 > 详细

加速计

时间:2015-07-08 12:23:43      阅读:214      评论:0      收藏:0      [点我收藏+]

// 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(@"摇一摇");

    }

}

加速计

原文:http://www.cnblogs.com/bluceZ/p/4629670.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!