onDeviceMotionChange方法第一次拿到的alpha值都是359.9997971985
发布于 6 年前 作者 lizeng 4586 次浏览 来自 问答

openDeviceMotionListening = () => {

    return new Promise(resolve => {

      const getAlpha = ({ alpha }) => {

        this.closeDeviceMotionListening()

        resolve(alpha)

      }


      Taro.startDeviceMotionListening()

      Taro.onDeviceMotionChange(getAlpha)

    })

  }


  /**

   * @description: 关闭获取用户手机设备方向

   * @return {*}

   */

  closeDeviceMotionListening = () => {

    // Taro.offDeviceMotionChange(); // TODO: 此方法报错

    Taro.stopDeviceMotionListening()

  }

const alpha = await openDeviceMotionListening ()

回到顶部