iOS12 - 使用WKWebView出现input键盘将页面上顶不下移
- 实际情况如下图
键盘弹起
键盘收起-
解决办法:
- 监听键盘的谈起和隐藏
/// 监听将要弹起 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardShow) name:UIKeyboardWillShowNotification object:nil]; /// 监听将要隐藏 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardHidden) name:UIKeyboardWillHideNotification object:nil]; 复制代码
- 监听方法中设置WKWebView的scrollview的contentOffset
/** 键盘谈起屏幕偏移量 */ @property (nonatomic, assign) CGPoint keyBoardPoint; #pragma mark - addObserverKeyboard /// 键盘将要弹起 - (void)keyBoardShow { CGPoint point = self.webView.scrollView.contentOffset; self.keyBoardPoint = point; } /// 键盘将要隐藏 - (void)keyBoardHidden { self.webView.scrollView.contentOffset = self.keyBoardPoint; } 复制代码
-
解决后效果