开发者

Retrieving Accelerometer Values?

I want to retrieve the iPh开发者_如何学Cone's accelerometer values and print them into a label.

Any help is appreciated.


Put this in viewDidLoad method of your ViewController which is UIAccelerometerDelegate:

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

Then add this method:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜