首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >陀螺仪数值(钛)

陀螺仪数值(钛)
EN

Stack Overflow用户
提问于 2014-04-23 17:17:36
回答 1查看 285关注 0票数 2

有没有办法拿到钛合金的陀螺仪数据?就像提供了一个访问accelerometer数据的应用程序接口一样。

EN

回答 1

Stack Overflow用户

发布于 2014-04-23 22:42:10

目前还没有,但是有一种相对简单的方法可以让您向已经使用CoreMotion的现有模块添加一些代码。

Ben Bahrenburg的模块,可在此处获得:https://github.com/benbahrenburg/Ti.CoreMotion/使用CoreMotion公开一个步长计数器。所以它已经有了引用的框架,以及模块的设置,构建等。这是困难的事情。所以只要把它拉下来,确保你可以自己./build.py它,然后暴露陀螺仪。完成后给他发一份公关,并回馈社区!

代码语言:javascript
复制
static const NSTimeInterval gyroMin = 0.01;

- (id)startGyro:(id)args {

     // Determine the update interval
     NSTimeInterval delta = 0.005;
     NSTimeInterval updateInterval = gyroMin + delta;

     // Create a CMMotionManager
     CMMotionManager *mManager = [(APLAppDelegate *)[[UIApplication sharedApplication] delegate] sharedManager];
     APLGyroGraphViewController * __weak weakSelf = self;

     // Check whether the gyroscope is available
     if ([mManager isGyroAvailable] == YES) {
          // Assign the update interval to the motion manager
          [mManager setGyroUpdateInterval:updateInterval];
          [mManager startGyroUpdatesToQueue:[NSOperationQueue mainQueue] withHandler:^(CMGyroData *gyroData, NSError *error) {
               // TODO: Do something with gyroData.rotationRate.x, y, and z.
          }];
     }
     return nil;
}

- (id)stopUpdates:(id)args {
     CMMotionManager *mManager = [(APLAppDelegate *)[[UIApplication sharedApplication] delegate] sharedManager];
     if ([mManager isGyroActive] == YES) {
          [mManager stopGyroUpdates];
     }
     return nil;
}

记住:使用Core Motion,您必须在设备上测试和调试您的应用程序。iOS模拟器中不支持加速度计或陀螺仪数据。

代码改编自:https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/motion_event_basics/motion_event_basics.html

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23239925

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档