Commit a90f3e0c authored by Alex朱枝文's avatar Alex朱枝文

添加原生调用h5方法,提供键盘调用,弹出和收起键盘事件

parent 65cb67ef
......@@ -303,6 +303,10 @@ class YHHomeWebViewController: YHBaseViewController, WKUIDelegate, WKNavigationD
}
getData()
updateNetWorkStatusUI(needReload: false)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardDidShow(_:)),
name: UIResponder.keyboardDidShowNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardDidHide(_:)),
name: UIResponder.keyboardDidHideNotification, object: nil)
}
......@@ -423,6 +427,22 @@ class YHHomeWebViewController: YHBaseViewController, WKUIDelegate, WKNavigationD
previewFileTool.openXLSXRemoteFile(urlString: urlString, fileName: "")
}
@objc func keyboardDidShow(_ notification: Notification) {
guard let userInfo = notification.userInfo,
let keyboardFrame = userInfo[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else { return }
let keyboardHeight = keyboardFrame.height
// 调用 H5 的 onKeyboardShow 方法,传递高度
let dict = ["height": "\(keyboardHeight)"]
webview.callHandler("onKeyboardHeightChanged", arguments: [dict])
}
@objc func keyboardDidHide(_ notification: Notification) {
// 调用 H5 的 onKeyboardHide 方法
let dict = ["height": "\(0)"]
webview.callHandler("onKeyboardHeightChanged", arguments: [dict])
}
// MARK: - WKNavigationDelegate
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
// if vcTitle == nil {
......
......@@ -77,6 +77,10 @@ class YHH5WebViewVC: YHBaseViewController, WKUIDelegate, WKNavigationDelegate {
override func viewDidLoad() {
super.viewDidLoad()
setupUI()
NotificationCenter.default.addObserver(self, selector: #selector(keyboardDidShow(_:)),
name: UIResponder.keyboardDidShowNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardDidHide(_:)),
name: UIResponder.keyboardDidHideNotification, object: nil)
}
override func viewWillAppear(_ animated: Bool) {
......@@ -456,6 +460,22 @@ private extension YHH5WebViewVC {
func navigationShouldPopOnGesture() -> Bool {
return !disableFullScreenGestureFlag
}
@objc func keyboardDidShow(_ notification: Notification) {
guard let userInfo = notification.userInfo,
let keyboardFrame = userInfo[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else { return }
let keyboardHeight = keyboardFrame.height
// 调用 H5 的 onKeyboardShow 方法,传递高度
let dict = ["height": "\(keyboardHeight)"]
webview.callHandler("onKeyboardHeightChanged", arguments: [dict])
}
@objc func keyboardDidHide(_ notification: Notification) {
// 调用 H5 的 onKeyboardHide 方法
let dict = ["height": "\(0)"]
webview.callHandler("onKeyboardHeightChanged", arguments: [dict])
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment