1

I have a WKWebView and I need to know when it is scrolled, so I bound its scroll view's delegate to my controller in order to use UIScrollView delegate methods:

self.myWebView.scrollView.delegate = self
...
func scrollViewDidScroll(_ scrollView: UIScrollView) {
    // Do stuff
    ...
}

It works well for almost every web pages but when the user does a google search, selects an AMP page and then scrolls up or down, I can't detect that scrolling.

Is there a way to know if an AMP page is scrolled?

Randy
  • 4,335
  • 3
  • 30
  • 64

2 Answers2

0

I hope this works (its working for me) , storing lastContentOffset's Y position and comparing it with current.

private var lastContentOffset: CGFloat = 0

func scrollViewDidScroll(_ scrollView: UIScrollView) {
    if (self.lastContentOffset > scrollView.contentOffset.y) {
         print("move up")
    }
    else if (self.lastContentOffset < scrollView.contentOffset.y) {
        print("move down")
    }
    self.lastContentOffset = scrollView.contentOffset.y
}
Nilomi Shah
  • 186
  • 7
0
class ViewController: WKNavigationDelegate, UIScrollViewDelegate

var webView: WKWebView!

override func loadView() {
        super.loadView()
        webView = WKWebView()
        webView.navigationDelegate = self
        webView.scrollView.delegate = self
        view = webView
    }

func scrollViewDidScroll(_ scrollView: UIScrollView) {  
        print(scrollView.contentOffset.y)
    }
Urvish Modi
  • 1,118
  • 10
  • 11