开发者

Retrieving Accelerometer Values?

开发者 https://www.devze.com 2023-02-24 07:34 出处:网络
I want to retrieve the iPh开发者_如何学Cone\'s accelerometer values and print them into a label.

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

精彩评论

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