Swift UIWebView检测滚动

Ale*_*ago 3 scroll uiwebview swift

我有一个UIWebView我正在渲染PDF的地方.如果pdf不在页面的开头,我需要一种隐藏GUI的方法,如果WebView点击顶部则需要再次显示.我怎么检查这个?

Nir*_*v D 8

您可以像这样使用scrollViewDelegate方法scrollViewDidScroll.

func scrollViewDidScroll(scrollView: UIScrollView) {

    if (scrollView.contentOffset.y == 0) {
        //Do what you want.
    }
}
Run Code Online (Sandbox Code Playgroud)

注意:不要忘了设定scrollView的代表webView这样self.webView.scrollView.delegate = self