IOS - 实时访问加速度计 XYZ 值

发布于 2024-11-28 12:36:45 字数 607 浏览 10 评论 0原文

我正在开发一个需要访问加速的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感情洁癖 2024-12-05 12:36:45

请阅读

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文