ios accelerometer values at any orientation

后端 未结 1 768
一个人的身影
一个人的身影 2021-01-23 01:13

Accelerometer values are provided with respect to the device orientation..

My goal is to get these values irrespective of the device position.

In a considered s

相关标签:
1条回答
  • 2021-01-23 01:43

    Its quite simple actually, just start generating device motion updates using a reference frame:

    - (void)startDeviceMotionUpdatesUsingReferenceFrame:(CMAttitudeReferenceFrame)referenceFrame
    

    Depending on what you want to achieve you can select one of the different options

    typedef enum {
       CMAttitudeReferenceFrameXArbitraryZVertical = 1 << 0,
       CMAttitudeReferenceFrameXArbitraryCorrectedZVertical = 1 << 1,
       CMAttitudeReferenceFrameXMagneticNorthZVertical = 1 << 2,
       CMAttitudeReferenceFrameXTrueNorthZVertical = 1 << 3
    } CMAttitudeReferenceFrame;
    

    For example, by using "CMAttitudeReferenceFrameXMagneticNorthZVertical" the readings you get from the acceleration would be constant regardless of the device position (they get aligned with "gravity" bellow" and "north" in front). I don't remember the exact reference position but i believe the "top of the phone" points north while the "screen of the phone" points up.

    0 讨论(0)
提交回复
热议问题