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 00ba964591563a4e608f952604e9f17dd5019e90..6ba260dfe301de29db15a0db8b278830f80f4aa0 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 }) + } + } +} +```