---
name: "onDeviceMotionChange"
mode: "kit"
versionRequirements:
  - { name: "BaseKit", version: "2.3.2" }
platform:
  - "iOS"
  - "Android"
async: true
title: "onDeviceMotionChange - 监听设备方向变化事件(数据为系统返回，双端精度可能不一致)"
---

## onDeviceMotionChange

> [VERSION] BaseKit >= 2.3.2

> [PLATFORM] iOS, Android

> ⚡ **支持 Promise 调用** — 不传 success / fail / complete 回调时，该方法返回 Promise。

### 描述

监听设备方向变化事件(数据为系统返回，双端精度可能不一致)

### 参数

`(listener: Function)`

| 参数 | 类型 | 必填 | 默认值 | 描述 |
| --- | --- | --- | --- | --- |
| `listener` | `(params: Object) => void` | 是 | - | 事件监听回调函数 |

##### onDeviceMotionChange.listener(params) 的属性

| 属性 | 类型 | 必填 | 默认值 | 最低版本 | 描述 |
| --- | --- | --- | --- | --- | --- |
| `alpha` | `number` | 是 | - | `2.3.2` | 当 手机坐标 X/Y 和 地球 X/Y 重合时，绕着 Z 轴转动的夹角为 alpha，范围值为 [0, 2*PI)。逆时针转动为正。 |
| `beta` | `number` | 是 | - | `2.3.2` | 当手机坐标 Y/Z 和地球 Y/Z 重合时，绕着 X 轴转动的夹角为 beta。范围值为 [-1*PI, PI) 。顶部朝着地球表面转动为正。也有可能朝着用户为正。 |
| `gamma` | `number` | 是 | - | `2.3.2` | 当手机 X/Z 和地球 X/Z 重合时，绕着 Y 轴转动的夹角为 gamma。范围值为 [-1*PI/2, PI/2)。右边朝着地球表面转动为正。 |
| `isParamCorrection` | `boolean` | 是 | - | `3.36.0` | 仅iOS有效，是否修正alpha值 |


### 示例代码

```tsx
// 设备方向事件需先开启监听才会回调，故先 start 再注册。
ty.startDeviceMotionListening({ interval: "normal" });

ty.onDeviceMotionChange(e => {
  console.log(e);
});
```
