简体   繁体   English

iOS混合应用程序WKWebView软键盘有时会覆盖输入字段

[英]iOS hybrid app WKWebView soft keyboard covering input fields sometimes

I am using a WKWebView as my web container on my iOS 8+ hybrid app. 我将WKWebView用作iOS 8+混合应用程序上的Web容器。

When an input field in the web container is focused and the soft keyboard comes up, the web view scrollview usually scrolls up automatically. 当Web容器中的输入字段处于焦点状态并且出现软键盘时,Web视图滚动视图通常会自动向上滚动。

However, sometimes the web view scrollview does not scroll up, and hides the input field behind the soft keyboard. 但是,有时Web视图滚动视图不会向上滚动,而是将输入字段隐藏在软键盘后面。 Only when I begin typing into the soft keyboard does the web view scrollview scroll up. 只有当我开始输入软键盘时,Web视图scrollview才会向上滚动。

The only solution I can think of is getting the input field position in the web view, and overriding the automatic scrolling provided by iOS. 我能想到的唯一解决方案是在Web视图中获取输入字段的位置,并覆盖iOS提供的自动滚动。 Are there any other solutions? 还有其他解决方案吗?

I ran into this issue as well and I was able to solve it by waiting until the keyboard finished animating/sliding up, then taking the height of the element that was focused on, then shifting the screen so that the bottom of that element was a set distance above the top of the keyboard. 我也遇到了这个问题,可以解决问题,方法是等到键盘完成动画/向上滑动后,再取下要聚焦的元素的高度,然后移动屏幕,使该元素的底部成为在键盘上方设置距离。

It requires a bit of math, but it is doable! 它需要一些数学运算,但是可行!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM