传感器 -UIAccelerometer

// ios 4 之前 UIAccelerometer

// ios 5 <CoreMotion/CoreMotion.h>

 

#import "ViewController.h"

//#import <CoreMotion/CoreMotion.h>

 

@interface ViewController ()<UIAccelerometerDelegate>

 

@end

 

@implementation ViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    // UIAccelerometer

    // 1. 创建单利对象

    UIAccelerometer *accelerpmeter = [UIAccelerometer sharedAccelerometer];

    

    // 2. 设置代理

    accelerpmeter.delegate = self;

    

    // 3. 设置采样间隔

    accelerpmeter.updateInterval = 1.0 / 20;

}

 

 

// 4. 实现代理方法

#pragma mark - UIAccelerometerDelegate

/**

 *  只要采集到数据, 就会调用一次(调用频率高)

 *

 *  @param accelerometer 单利对象

 *  @param acceleration  <#acceleration description#>

 */

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

//{

//    LogRed(@"%f --- %f --- %f ----%f",acceleration.timestamp, acceleration.x, acceleration.y, acceleration.z);

//}

 

@end

posted @ 2015-09-23 18:42  guangleijia  阅读(201)  评论(0编辑  收藏  举报