gpt4 book ai didi

ios - 无法将类型 '(CMDeviceMotion?, NSError?) -> ()' 的值转换为预期的参数类型 'CMDeviceMotionH

转载 作者:行者123 更新时间:2023-11-28 11:58:29 25 4
gpt4 key购买 nike

我最近升级了我的 xcode。我目前使用 9.2我正在使用 CMMotionManger,此错误显示在新版本中。我尝试解决它但找不到解决方案。

func startCameraTracking() {
motionManager.deviceMotionUpdateInterval = 1.0 / 60.0


motionManager.startDeviceMotionUpdatesToQueue(OperationQueue.main) {
[weak self](data: CMDeviceMotion?, error: NSError?) in

guard let data = data else { return }

let attitude: CMAttitude = data.attitude
self?.cameraNode.eulerAngles = SCNVector3Make(Float(attitude.roll + M_PI/2.0), -Float(attitude.yaw), -Float(attitude.pitch))
}
}

最佳答案

根据 Michael 的建议,您最好查看最新的引用资料:

(startDeviceMotionUpdatesToQueue(_: withHandler:) 重命名为 startDeviceMotionUpdates(to:withHandler:)。)

startDeviceMotionUpdates(to:withHandler:)

Declaration

func startDeviceMotionUpdates(to queue: OperationQueue, 
withHandler handler: @escaping CMDeviceMotionHandler)

CMDeviceMotionHandler

Declaration

typealias CMDeviceMotionHandler = (CMDeviceMotion?, Error?) -> Void

对于 startDeviceMotionUpdates(to:withHandler:) 的第二个参数,您需要传递一个带有 CMDeviceMotion?Error? 的闭包,不是 NSError?:

func startCameraTracking() {
motionManager.deviceMotionUpdateInterval = 1.0 / 60.0

motionManager.startDeviceMotionUpdates(to: OperationQueue.main) {
[weak self](data: CMDeviceMotion?, error: Error?) in

guard let data = data else { return }

let attitude: CMAttitude = data.attitude
self?.cameraNode.eulerAngles = SCNVector3Make(Float(attitude.roll + .pi/2.0), -Float(attitude.yaw), -Float(attitude.pitch))
}
}

关于ios - 无法将类型 '(CMDeviceMotion?, NSError?) -> ()' 的值转换为预期的参数类型 'CMDeviceMotionH,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50471072/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com