【问题标题】:Gyroscope value in titanium陀螺仪值以钛计
【发布时间】:2014-04-23 09:17:35
【问题描述】:

有什么方法可以获取钛金属中的陀螺仪数据?就像有一个 API 可以访问 accelerometer 数据一样。

【问题讨论】:

    标签: javascript titanium titanium-mobile gyroscope


    【解决方案1】:

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

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

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多