onGyroscopeChange(listener: Function)

版本要求:
BaseKit≥2.3.2@ray-js/ray≥0.3.23
支持平台:
iOSAndroid
import { onGyroscopeChange } from '@ray-js/ray';

// Promise 调用
try {
  const res = await onGyroscopeChange({ ...params });
  console.log(res);
} catch (err) {
  console.log(err.errorMsg);
}

描述

监听陀螺仪数据变化事件(数据为系统返回,双端精度可能不一致)

参数

参数类型必填说明
是

返回值

无

示例代码

import { onGyroscopeChange, startGyroscope } from '@ray-js/ray'

// 监听陀螺仪数据变化:先注册 onGyroscopeChange,再 startGyroscope 启动传感器,x/y/z 数据即通过回调返回
onGyroscopeChange(e => {
  console.log("陀螺仪 x/y/z:", e.x, e.y, e.z);
});
startGyroscope({
  interval: "normal",
  success: () => console.log("已开始监听陀螺仪"),
  fail: error => console.error(error),
});