【问题标题】:selecting attitude reference frame in IOS 10 coremotion using swift 3使用 swift 3 在 IOS 10 coremotion 中选择姿态参考系
【发布时间】:2016-10-14 15:30:17
【问题描述】:

我正在尝试使用 CMMotionManager 来更新 scenekit 中摄像机视点的姿态。我可以使用默认的工作引用获得以下代码。

manager.deviceMotionUpdateInterval = 0.01
manager.startDeviceMotionUpdates(to: motionQueue, withHandler:{ deviceManager, error in
                if (deviceManager?.attitude) != nil {
                    let rotation = deviceManager?.attitude.quaternion

                    OperationQueue.main.addOperation {
                        self.cameraNode.rotation = SCNVector4(rotation!.x,rotation!.y,rotation!.z,rotation!.w)
                    }
                }

        })

但是我无法让 startDeviceMotionUpdates 与选定的参考框架一起工作,如下所示:

manager.deviceMotionUpdateInterval = 0.01
manager.startDeviceMotionUpdates(using: CMAttitudeReferenceFrameXMagneticNorthZVertical, to: motionQueue, withHandler:{ deviceManager, error in
            if (deviceManager?.attitude) != nil {
                let rotation = deviceManager?.attitude.quaternion

                OperationQueue.main.addOperation {
                    self.cameraNode.rotation = SCNVector4(rotation!.x,rotation!.y,rotation!.z,rotation!.w)
                }
            }

        })

我收到的错误是:

Use of unresolved identifier 'CMAttitudeReferenceFrameXMagneticNorthZVertical'

我也收到其他参考帧的类似错误消息。任何人都可以阐明 startDeviceMotionUpdates 函数的“使用:”参数的使用吗?我发现的所有示例都是针对旧版本的 swift 或 Objective c,因此很可能这只是不理解 Swift 3 语法的问题。

【问题讨论】:

    标签: swift3 ios10 core-motion


    【解决方案1】:

    经过一些额外的摆弄后,我发现 using 参数需要新的 CMAttitudeReferenceFrame 结构的成员。即它应该被传递为:

    manager.deviceMotionUpdateInterval = 0.01
    manager.startDeviceMotionUpdates(using: CMAttitudeReferenceFrame.xMagneticNorthZVertical
                ,to: motionQueue, withHandler:{
                deviceManager, error in
                if (deviceManager?.attitude) != nil {
                    let rotation = deviceManager?.attitude.quaternion
    
                    OperationQueue.main.addOperation {
                        self.cameraNode.rotation = SCNVector4(rotation!.x,rotation!.y,rotation!.z,rotation!.w)
                    }
                }
    
            })
    

    这是对早期版本的更改,允许直接使用常量,例如“CMAttitudeReferenceFrameXMagneticNorthZVertical”

    【讨论】:

      猜你喜欢
      • 2016-07-29
      • 2011-12-16
      • 2018-02-02
      • 1970-01-01
      • 2017-02-11
      • 2017-02-15
      • 1970-01-01
      • 2017-03-19
      • 1970-01-01
      相关资源
      最近更新 更多