未验证 提交 f30f69af 编写于 作者: O openharmony_ci 提交者: Gitee

!14281 【master】增加内容比例设置接口

Merge pull request !14281 from chenhaiying/master
......@@ -4341,6 +4341,176 @@ promise.then(()=> {
console.error('Failed to raise the window to app top. Cause: ' + JSON.stringify(err));
});
```
### setAspectRatio<sup>10+</sup>
setAspectRatio(ratio: number): Promise&lt;void&gt;
设置窗口内容布局的比例,使用Promise异步回调。
仅应用主窗口支持此接口功能,比例参数将持久化保存,关闭应用或重启设备设置的比例仍然生效。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------------ | ------- | ---- | ------------------------------------------------------------ |
| ratio | number | 是 | 除边框装饰之外的窗口内容布局的宽高比,取值范围为大于0。 |
**返回值:**
| 类型 | 说明 |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**错误码:**
以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)
| 错误码ID | 错误信息 |
| ------- | -------------------------------------------- |
| 1300002 | This window state is abnormal. |
| 1300004 | Unauthorized operation. |
**示例:**
```js
try {
let ratio = 1.0;
let promise = windowClass.setAspectRatio(ratio);
promise.then(()=> {
console.info('Succeeded in setting aspect ratio of window.');
}).catch((err)=>{
console.error('Failed to set the aspect ratio of window. Cause:' + JSON.stringify(err));
});
} catch (exception) {
console.error('Failed to set the aspect ratio of window. Cause: ' + JSON.stringify(exception));
}
```
### setAspectRatio<sup>10+</sup>
setAspectRatio(ratio: number, callback: AsyncCallback&lt;void&gt;): void
设置窗口内容布局的比例,使用callback异步回调。
仅应用主窗口支持此接口功能,比例参数将持久化保存,关闭应用或重启设备设置的比例仍然生效。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------------ | ------- | ---- | ------------------------------------------------------------ |
| ratio | number | 是 | 除边框装饰之外的窗口内容布局的宽高比,取值范围为大于0。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
**错误码:**
以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)
| 错误码ID | 错误信息 |
| ------- | -------------------------------------------- |
| 1300002 | This window state is abnormal. |
| 1300004 | Unauthorized operation. |
**示例:**
```js
try {
let ratio = 1.0;
windowClass.setAspectRatio(ratio, (err) => {
if (err.code) {
console.error('Failed to set the aspect ratio of window. Cause:' + JSON.stringify(err));
return;
}
console.error('Failed to set the aspect ratio of window. Cause:' + JSON.stringify(err));
});
} catch (exception) {
console.error('Failed to set the aspect ratio of window. Cause: ' + JSON.stringify(exception));
}
```
### resetAspectRatio<sup>10+</sup>
resetAspectRatio(): Promise&lt;void&gt;
取消设置窗口内容布局的比例,使用Promise异步回调。
仅应用主窗口支持此接口功能,调用后将清除持久化储存的比例信息。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**返回值:**
| 类型 | 说明 |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**错误码:**
以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)
| 错误码ID | 错误信息 |
| ------- | -------------------------------------------- |
| 1300002 | This window state is abnormal. |
| 1300004 | Unauthorized operation. |
**示例:**
```js
try {
let promise = windowClass.resetAspectRatio();
promise.then(()=> {
console.info('Succeeded in resetting aspect ratio of window.');
}).catch((err)=>{
console.error('Failed to reset the aspect ratio of window. Cause:' + JSON.stringify(err));
});
} catch (exception) {
console.error('Failed to reset the aspect ratio of window. Cause: ' + JSON.stringify(exception));
}
```
### resetAspectRatio<sup>10+</sup>
resetAspectRatio(callback: AsyncCallback&lt;void&gt;): void
取消设置窗口内容布局的比例,使用callback异步回调。
仅应用主窗口支持此接口功能,调用后将清除持久化储存的比例信息。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------------ | ------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
**错误码:**
以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)
| 错误码ID | 错误信息 |
| ------- | -------------------------------------------- |
| 1300002 | This window state is abnormal. |
| 1300004 | Unauthorized operation. |
**示例:**
```js
try {
windowClass.resetAspectRatio((err) => {
if (err.code) {
console.error('Failed to reset the aspect ratio of window. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in resetting aspect ratio of window.');
});
} catch (exception) {
console.error('Failed to reset the aspect ratio of window. Cause: ' + JSON.stringify(exception));
}
```
### show<sup>(deprecated)</sup>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册