Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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:

(重现问题的步骤如下:)

  1. Load the WKwebView page and execute the refresh function.

    (加载WKwebView页面并执行刷新功能。)

  2. Scroll to the bottom screen to see if there is a bounce.

    (滚动到底部屏幕,查看是否有反弹。)

  3. If it works normally, go to a different screen.

    (如果正常,请转到其他屏幕。)

    location.href = "./other.html";
  4. Scroll from another screen to the bottom screen to see if there is a bounce.

    (从另一个屏幕滚动到底部屏幕以查看是否有反弹。)

  5. If there is no bounce normally, please return to the screen.

    (如果正常情况下没有弹跳,请返回屏幕。)

    history.back()
  6. 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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
190 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.

(有了这个添加,反弹值就重新初始化了,刷新工作了。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...