我想检索iPhone的加速度计值并将其打印成标签。
感谢任何帮助。
答案 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
}