检索加速度计值?

时间:2011-04-14 06:43:48

标签: iphone xcode accelerometer

我想检索iPhone的加速度计值并将其打印成标签。

感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

将它放在ViewController的viewDidLoad方法中,即UIAccelerometerDelegate:

UIAccelerometer *accelerometer = [UIAccelerometer sharedAccelerometer];
accelerometer.updateInterval = 1.0f/60.0f;
accelerometer.delegate = self;

然后添加此方法:

-(void)accelerometer:(UIAccelerometer *)acelerometer didAccelerate:(UIAcceleration*)acceleration 
{
    // here you can use acceleration.x, acceleration.y, acceleration.z 
}