onDeviceMotionChange方法第一次拿到的alpha值都是359.9997971985

发布于 7 年前作者 lizeng4650 次浏览最后编辑 7 年前来自 ask

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 ()

0 回复
暂无回复