---
name: "setPageOrientation"
mode: "kit"
versionRequirements:
  - { name: "MiniKit", version: "2.4.1" }
  - { name: "@ray-js/ray", version: "0.3.23" }
platform:
  - "iOS"
  - "Android"
async: true
title: "setPageOrientation - 屏幕旋转设置，auto / portrait / landscape。pad 模式下不支持屏幕旋转"
---

## setPageOrientation

> [VERSION] MiniKit >= 2.4.1 | @ray-js/ray >= 0.3.23

> [PLATFORM] iOS, Android

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

### 描述

屏幕旋转设置，auto / portrait / landscape。pad模式下不支持屏幕旋转

### 参数

| 属性 | 类型 | 必填 | 默认值 | 最低版本 | 描述 |
| --- | --- | --- | --- | --- | --- |
| `pageOrientation` | `string` | 是 | - | `2.4.1` | 屏幕旋转设置， auto / portrait / landscape (默认landscape-right) |
| `reverse` | `boolean` | 否 | - | `3.24.0` | 是否反向旋转，仅在pageOrientation为landscape时有效，默认false |
| `complete` | `() => void` | 否 | - | - | 接口调用结束的回调函数（调用成功、失败都会执行） |
| `success` | `() => void` | 否 | - | - | 接口调用成功的回调函数 |
| `fail` | `(params: Object) => void` ↓见下方 | 否 | - | - | 接口调用失败的回调函数 |

#### fail 回调参数

| 属性 | 类型 | 描述 |
| --- | --- | --- |
| `errorMsg` | `string` | 错误信息 |
| `errorCode` | `string \| number` | 错误码 |
| `innerError` | `Object` | 错误扩展 |

##### fail(params).innerError 的属性

| 属性 | 类型 | 描述 |
| --- | --- | --- |
| `errorCode` | `string \| number` | 错误扩展码 |
| `errorMsg` | `string` | 错误扩展信息 |


### 示例代码

#### Demo

```tsx
import { setPageOrientation } from '@ray-js/ray'

setPageOrientation({
  pageOrientation: "portrait",
  reverse: false,
  success: data => { console.log(data); },
  fail: error => { console.error(error); },
});
```
