开发者

IOS - Accessing Accelerometer X Y Z Values in Realtime

I am working on an iphone/ipod touch app that needs to access the acceleration. I am kind of a newb when it comes to iOS development, I usually develop Android applications.

My first question, is how do I instantiatate the accelerometer? In Android I know i can do it like this:

mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);

mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);

My second question is with the handling of accelerometer events, specifically getting the X Y and Z values from the accelerometer state. In android I did the following:

public void onSensorChanged(SensorEvent event) 
{
    final double curX = event.values[0];
    final double curY = event.values[1];
    final double curZ = ev开发者_如何学运维ent.values[2];
    //more code stuff
}

Any help would be greatly appreciated :-)


Please read the event handling documentation which contains lots of information and further reading about the accelerometer.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜