2014-04-23 121 views

回答

1

目前沒有,但是有一種相對簡單的方法可以向已經使用CoreMotion的現有模塊添加一些代碼。

本巴林堡的模塊,可在這裏: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