I use the refresh function in WKWebview
.
(我在WKWebview
使用刷新功能。)
(执行刷新时功能正常。)
But when I load anotherhtml
file and come back, it is not refreshed.(但是,当我加载另一个html
文件并返回时,它不会刷新。)
@IBOutlet var myWebView: WKWebView!
var refController:UIRefreshControl = UIRefreshControl()
override func viewDidLoad() {
super.viewDidLoad()
myWebView.uiDelegate = self
myWebView.navigationDelegate = self
myWebView.scrollView.delegate = self
refController.bounds = CGRect.init(x: 0.0, y: 50.0, width: refController.bounds.size.width, height: refController.bounds.size.height)
refController.addTarget(self, action: #selector(self.webviewRefresh(refresh:)), for: .valueChanged)
myWebView.scrollView.addSubview(refController)
...
}
@objc func webviewRefresh(refresh:UIRefreshControl){
refController.endRefreshing()
myWebView.reload()
}
extension mainWebViewController: UIScrollViewDelegate{
func scrollViewDidScroll(_ scrollView: UIScrollView) {
print("come in ??")
if currentHtmlFileName == "Main.html" {
scrollView.bounces = (scrollView.contentOffset.y <= 0)
} else {
scrollView.bounces = false
}
}
}
As you can see from my code, my WKWebview
is scrolling, and the function is executed.
(从代码中可以看到,我的WKWebview
正在滚动,并且函数已执行。)
(但是,当在另一个屏幕上激活该功能并返回该功能时,不会调用该功能,刷新也不会起作用。)
The steps for reproducing a problem are as follows:
(重现问题的步骤如下:)
- Load the WKwebView page and execute the refresh function.
(加载WKwebView页面并执行刷新功能。)
- Scroll to the bottom screen to see if there is a bounce.
(滚动到底部屏幕,查看是否有反弹。)
- If it works normally, go to a different screen.
(如果正常,请转到其他屏幕。)
location.href = "./other.html";
- Scroll from another screen to the bottom screen to see if there is a bounce.
(从另一个屏幕滚动到底部屏幕以查看是否有反弹。)
- If there is no bounce normally, please return to the screen.
(如果正常情况下没有弹跳,请返回屏幕。)
history.back()
- And run the refresh function again.
(并再次运行刷新功能。)
In my case, I have a bounce, but the refresh does not run, and the function is not called.
(就我而言,我有跳动,但刷新未运行,并且未调用该函数。)
Has anyone solved the same problem as me?
(有谁解决过与我相同的问题?)
Is this a bug???(这是一个错误吗???)
ask by hong develop translate from so