[英]Why do not working UIRefreshControl in Swift?
I use the refresh function in WKWebview
.我在
WKWebview
使用刷新功能。 The function is normal when performing a refresh.执行刷新时该功能正常。 But when I load another
html
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
正在滚动,并且执行了该功能。 However, when the function is activated on a different screen and returned, the function is not called, nor is the refresh working.但是,当该函数在不同的屏幕上被激活并返回时,该函数不会被调用,刷新也不会起作用。
The steps for reproducing a problem are as follows:重现问题的步骤如下:
location.href = "./other.html";
history.back()
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???
这是bug吗???
I thought a lot about this problem.我想了很多关于这个问题。 So my conclusion is
history.back()
does not change the value of the bounce
.所以我的结论是
history.back()
不会改变bounce
的价值。 Therefore, the bounce
value is false
.因此,
bounce
值为false
。
So I thought I should reinitialize this value.所以我想我应该重新初始化这个值。 So I added a function in the section that completes page navigation.
所以我在完成页面导航的部分添加了一个功能。
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
if currentHtmlFileName == "Main.html" {
scrollViewDidScroll(myWebView.scrollView)
}
}
With this addition, the bounce value was reinitialized, and my refresh worked.有了这个添加,反弹值被重新初始化,我的刷新工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.