From 12e623cc196064432a9103651ed9f4ad53ebf046 Mon Sep 17 00:00:00 2001 From: KeeGitee Date: Tue, 17 Jun 2025 09:52:06 +0800 Subject: [PATCH] =?UTF-8?q?web=E7=BB=84=E4=BB=B6=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E8=A7=86=E5=8F=A3=E9=81=BF=E8=AE=A9=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: KeeGitee --- .../arkts-apis-webview-WebviewController.md | 67 ++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/zh-cn/application-dev/reference/apis-arkweb/arkts-apis-webview-WebviewController.md b/zh-cn/application-dev/reference/apis-arkweb/arkts-apis-webview-WebviewController.md index 00ba9645915..6ba260dfe30 100644 --- a/zh-cn/application-dev/reference/apis-arkweb/arkts-apis-webview-WebviewController.md +++ b/zh-cn/application-dev/reference/apis-arkweb/arkts-apis-webview-WebviewController.md @@ -9185,4 +9185,69 @@ struct WebComponent { } } } -``` \ No newline at end of file +``` + +## avoidVisibleViewportBottom20+ + +avoidVisibleViewportBottom(avoidHeight: number): void + +设置Web网页可视视口底部避让高度。 + +> **说明:** +> +> - avoidHeight有效值区间为[0, Web组件高度],超出有效值区间时取边界值。 +> - 该接口高度设置为非0时,Web组件位置和尺寸不变,可视视口向上避让avoidHeight,表现为Web网页内容抬升avoidHeight。该接口一般用于应用自定义网页底部避让区,不建议和点击web网页可编辑区拉起键盘的场景同时使用。同时使用时,键盘弹起避让模式将使用OVERLAYS_CONTENT。 +> - 该接口高度设置为0时,Web网页内容可恢复,键盘弹起避让模式将使用[keyboardAvoidMode()](./arkts-basic-components-web-attributes.md#keyboardavoidmode12)声明的模式。 + +**系统能力:** SystemCapability.Web.Webview.Core + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ------ | -------- | ---- | ---------------------- | +| avoidHeight | number | 是 | 设置Web网页可视视口底部避让高度。
默认值:0
单位:vp
合法取值范围:0~Web组件高度
非法值设置行为:超出合法取值范围时取边界值。 | + +**错误码:** + +以下错误码的详细介绍请参见[webview错误码](errorcode-webview.md)。 + +| 错误码ID | 错误信息 | +| -------- | ------------------------------------------------------------ | +| 17100001 | Init error. The WebviewController must be associated with a Web component. | + +**示例:** + +```ts +// xxx.ets +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + avoidHeight: number = 100; + + build() { + Column() { + Button('avoid') + .onClick(() => { + try { + this.controller.avoidVisibleViewportBottom(this.avoidHeight); + } catch (error) { + console.error(`ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('reset') + .onClick(() => { + try { + this.controller.avoidVisibleViewportBottom(0); + } catch (error) { + console.error(`ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: 'www.example.com', controller: this.controller }) + } + } +} +``` -- Gitee