【问题标题】:How do I correct startGyroscopeUpdatesToQueue error in swift如何快速纠正 startGyroscopeUpdatesToQueue 错误
【发布时间】:2015-09-18 22:33:02
【问题描述】:

我刚刚将 xcode 更新到 7.0,我现有的陀螺仪代码现在给了我一个错误。我已经玩了几个小时了,但我无法弄清楚。我该如何纠正这个问题?

    override func viewDidLoad() {

    if motionManager.gyroAvailable {

        motionManager.startGyroUpdates()
        motionManager.deviceMotionUpdateInterval = 0.2
        motionManager.startDeviceMotionUpdates()

        motionManager.gyroUpdateInterval = 0.2
        motionManager.startGyroUpdatesToQueue(NSOperationQueue.currentQueue()!) {
            [weak self] (gyroData: CMGyroData!, error: NSError!) in

            self!.outputRotationData(gyroData.rotationRate)
            if error != nil {
                print("\(error)")
            }

        }
    } else {
        print("gyro not avail")
    }

    super.viewDidLoad()
}

错误 1: 无法将类型“(CMRotationRate,错误:NSError.Type)”的值转换为预期的参数类型“CMGyroHandler”(又名“(可选,可选)->()”)

【问题讨论】:

    标签: swift ios8 gyroscope


    【解决方案1】:
    motionManager.startGyroUpdatesToQueue(NSOperationQueue.mainQueue(), withHandler: { (gyroData, NSError) -> Void in
        self.outputRotationData(gyroData!.rotationRate)            
    })
    

    【讨论】:

      猜你喜欢
      • 2011-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-25
      • 2010-10-18
      • 1970-01-01
      • 2017-05-15
      • 2014-06-03
      相关资源
      最近更新 更多