Can anybo开发者_JAVA百科dy provide me with an example on how to use the gyroscope with Monotouch? I can't figure out how to respond to gyro update events.
Thanks!
Here is a simple example:
using MonoTouch.CoreMotion;
//..
CMMotionManager motionManager;
private void StartGyro()
{
motionManager = new CMMotionManager();
motionManager.GyroUpdateInterval = 1/10;
if (motionManager.GyroAvailable)
{
motionManager.StartGyroUpdates(NSOperationQueue.MainQueue, GyroData_Received);
}
}
private void GyroData_Received(CMGyroData gyroData, NSError error)
{
Console.WriteLine("rotation rate x: {0}, y: {1}, z: {2}",
gyroData.RotationRate.x, gyroData.RotationRate.y, gyroData.RotationRate.z);
}
Each of the three values of the RotationRate property of the CMGyroData instance is the amount of rotation angle per second on each axis, in radians.
精彩评论