【问题标题】:Using the gyroscope with Monotouch?将陀螺仪与 Monotouch 一起使用?
【发布时间】:2011-07-20 03:09:55
【问题描述】:

谁能给我提供一个关于如何将陀螺仪与 Monotouch 一起使用的示例?我不知道如何响应陀螺仪更新事件。

谢谢!

【问题讨论】:

    标签: iphone xamarin.ios gyroscope


    【解决方案1】:

    这是一个简单的例子:

    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);
    }
    

    CMGyroData 实例的 RotationRate 属性的三个值中的每一个都是每个轴上每秒的旋转角度量,以弧度为单位。

    【讨论】:

    • 谢谢!我知道这是直截了当的事情,但无法将各个部分拼凑在一起。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多