IOS - 实时访问加速度计 XYZ 值
我正在开发一个需要访问加速的 iphone/ipod touch 应用程序。对于iOS开发来说,我是一个新手,我通常开发Android应用程序。
我的第一个问题是如何实例化加速度计?在 Android 中,我知道我可以这样做:
mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
我的第二个问题是处理加速度计事件,特别是从加速度计状态获取 XY 和 Z 值。在android中我做了以下操作:
public void onSensorChanged(SensorEvent event)
{
final double curX = event.values[0];
final double curY = event.values[1];
final double curZ = event.values[2];
//more code stuff
}
任何帮助将不胜感激:-)
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 = event.values[2];
//more code stuff
}
Any help would be greatly appreciated :-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请阅读
Please read the event handling documentation which contains lots of information and further reading about the accelerometer.