Swift -> WKWebView scroll listener, set the scroll position

 

Add  UIScrollViewDelegate  delegate

class ViewController: UIViewControllerUIScrollViewDelegate {

 

}

 

add proxy=SELF to WebView 

 

webView.scrollView.delegate = self

 

Then just like other WEBVIEW listeners, for example: Triggered whenever there is scrolling,

 

    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        print("do scroll")
        //Print the real-time position of the current scroll bar
        print(scrollView.contentOffset.y)
    }

 

 ** Manually set the webView scroll bar position

webView.scrollView.contentOffset.y -= 10

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326180846&siteId=291194637