> For AI agents: the complete documentation index is available at /apps-plugin/docs/llms.txt, the full documentation bundle is available at /apps-plugin/docs/llms-full.txt.

# onDeviceMotionChange

监听设备方向变化事件。

## 扫码预览

![扫码预览 onDeviceMotionChange](https://api.qrserver.com/v1/create-qr-code/?size=200x200\&data=doubao%3A%2F%2Fdoubao_apps%3Fapp_id%3Ddb_1McM5Ni%26path%3D%252Fpages%252Fapi%252Fdevice%252Fdevice-motion%252Findex)

## 支持版本

前端库版本不低于 `0.0.29`。

## 支持平台

<table>
<thead>
<tr><th>平台</th><th>支持情况</th></tr>
</thead>
<tbody>
<tr><td>Android</td><td>支持</td></tr>
<tr><td>iOS</td><td>支持</td></tr>
<tr><td>PC</td><td>不支持</td></tr>
<tr><td>HarmonyOS</td><td>不支持</td></tr>
</tbody>
</table>

## 支持场景

<table>
<thead>
<tr><th>场景</th><th>支持情况</th></tr>
</thead>
<tbody>
<tr><td>页面</td><td>支持</td></tr>
<tr><td>卡片</td><td>不支持</td></tr>
</tbody>
</table>

## 接入准备

### 前置条件

- 调用 `startDeviceMotionListening` 后事件才会持续回调

## 使用说明

- 取消函数只移除本地回调，需要停止采集时调用 `stopDeviceMotionListening`

## 调用方式

### 事件监听 API

```typescript
onDeviceMotionChange(callback: (event: DeviceMotionChangeEvent) => void): () => void
```

## 入参

无。

## 调用示例

```ts
import { onDeviceMotionChange } from '@doubao-dev/framework/api';

const off = onDeviceMotionChange(({ alpha, beta, gamma }) => {
  console.log(alpha, beta, gamma);
});

off();
```

## 回调参数

<table>
<thead>
<tr><th>名称</th><th>类型</th><th>必返</th><th>说明</th></tr>
</thead>
<tbody>
<tr><td><code>event.alpha</code></td><td><code>number</code></td><td>是</td><td>当手机坐标 X/Y 和地球坐标 X/Y 重合时，绕 Z 轴转动的夹角。<br>范围为 [0, 2π)，逆时针转动为正。</td></tr>
<tr><td><code>event.beta</code></td><td><code>number</code></td><td>是</td><td>当手机坐标 Y/Z 和地球坐标 Y/Z 重合时，绕 X 轴转动的夹角。<br>范围为 [-π, π)。</td></tr>
<tr><td><code>event.gamma</code></td><td><code>number</code></td><td>是</td><td>当手机坐标 X/Z 和地球坐标 X/Z 重合时，绕 Y 轴转动的夹角。<br>范围为 [-π/2, π/2)。</td></tr>
</tbody>
</table>

## 返回值

返回取消当前监听函数的函数。

### 回调示例

```json
{
  "alpha": 1.57,
  "beta": 0.12,
  "gamma": -0.05
}
```
