diff --git a/zh-cn/application-dev/reference/apis/js-apis-window.md b/zh-cn/application-dev/reference/apis/js-apis-window.md index 9513eafeb0d180d7d99329aab40d96920c56f22e..d763a5292c94f5b7bcd53f2c865786d45bcabd6c 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-window.md +++ b/zh-cn/application-dev/reference/apis/js-apis-window.md @@ -98,6 +98,27 @@ import window from '@ohos.window'; | isNavigationBarLightIcon7+ | boolean | 否 | 否 | 导航栏图标是否为高亮状态。 | | navigationBarContentColor8+ | string | 否 | 是 | 导航栏文字颜色。 | +## Orientation9+ + +窗口显示方向类型枚举。 + +**系统能力:** SystemCapability.WindowManager.WindowManager.Core + +| 名称 | 值 | 说明 | +| ------------------------------------- | ---- | ----------------------------- | +| UNSPECIFIED | 0 | 表示未定义方向模式,由系统判定。 | +| PORTRAIT | 1 | 表示竖屏显示模式。 | +| LANDSCAPE | 2 | 表示横屏显示模式。 | +| PORTAIT_INVERTED | 3 | 表示反向竖屏显示模式。 | +| LANDSCAPE_INVERTED | 4 | 表示反向横屏显示模式。 | +| AUTO_ROTATION | 5 | 表示传感器自动旋转模式。 | +| AUTO_ROTATION_PORTRAIT | 6 | 表示传感器自动竖向旋转模式。 | +| AUTO_ROTATION_LANDSCAPE | 7 | 表示传感器自动横向旋转模式。 | +| AUTO_ROTATION_RESTRICTED | 8 | 表示受开关控制的自动旋转模式。 | +| AUTO_ROTATION_PORTRAIT_RESTRICTED | 9 | 表示受开关控制的自动竖向旋转模式。 | +| AUTO_ROTATION_LANDSCAPE_RESTRICTED | 10 | 表述受开关控制的自动横向旋转模式。 | +| LOCKED | 11 | 表示锁定模式。 | + ## SystemBarRegionTint8+ 单个导航栏或状态栏回调信息。 @@ -1471,6 +1492,66 @@ promise.then((data)=> { }); ``` +### setPreferredOrientation9+ + +setPreferredOrientation(orientation: Orientation, callback: AsyncCallback<void>): void + +设置窗口的显示方向属性,使用callback异步回调。 + +**系统能力:** SystemCapability.WindowManager.WindowManager.Core + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ------------------- | ------------------------------------------- | ---- | ---------------------- | +| Orientation | [Orientation](#orientation9) | 是 | 窗口显示方向的属性。 | +| callback | AsyncCallback<void> | 是 | 回调函数。 | + +**示例:** + +```js +var orientation = window.Orientation.AUTO_ROTATION; +windowClass.setPreferredOrientation(orientation, (err, data) => { + if (err.code) { + console.error('Failed to set window orientation. Cause: ' + JSON.stringify(err)); + return; + } + console.info('Succeeded in setting window orientation. Data: ' + JSON.stringify(data)); +}); +``` + +### setPreferredOrientation9+ + +setPreferredOrientation(orientation: Orientation): Promise<void> + +设置窗口的显示方向属性,使用Promise异步回调。 + +**系统能力:** SystemCapability.WindowManager.WindowManager.Core + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ------------------- | ------------------------------------------- | ---- | ---------------------- | +| Orientation | [Orientation](#orientation9) | 是 | 窗口显示方向的属性。 | + +**返回值:** + +| 类型 | 说明 | +| ------------------- | ------------------------- | +| Promise<void> | 无返回结果的Promise对象。 | + +**示例:** + +```js +var orientation = window.Orientation.AUTO_ROTATION; +let promise = windowClass.setPreferredOrientation(orientation); +promise.then((data)=> { + console.info('Succeeded in setting the window orientation. Data: ' + JSON.stringify(data)); +}).catch((err)=>{ + console.error('Failed to set the window orientation. Cause: ' + JSON.stringify(err)); +}); +``` + ### loadContent7+ loadContent(path: string, callback: AsyncCallback<void>): void