显示键盘时,WKWebView如何禁用AdjustedContentInset?

时间:2020-07-28 14:29:00

标签: ios wkwebview

如果在显示WKWebView时打开键盘,它将自动将AdjustedContentInset添加到ScrollView。但是问题是,如果我自己操作键盘,它仍然会添加AdjustedContentInset。我该如何解决?

1 个答案:

答案 0 :(得分:1)

如果从WKWebView中删除处理键盘的观察者,它将停止添加AdjustedContentInset:

    NotificationCenter.default.removeObserver(self.webView, name: UIResponder.keyboardWillChangeFrameNotification, object: nil)
    NotificationCenter.default.removeObserver(self.webView, name: UIResponder.keyboardWillShowNotification, object: nil)
    NotificationCenter.default.removeObserver(self.webView, name: UIResponder.keyboardWillHideNotification, object: nil)