如何查找webview中的滚动位置是否滚动到结尾或直到顶部?

时间:2014-01-22 22:21:49

标签: ios objective-c uiwebview uiscrollview uiwebviewdelegate

如何查看webview是否已滚动到顶部或直到最后?

对于这两种情况我需要进行哪些检查以保持滚动偏移以及哪个函数/委托menthod,我是否需要检查它以便我知道用户已滚动到结尾或直到顶部?

实际上我必须为此目的在屏幕上更改UIWebview和其他视图的框架。

1 个答案:

答案 0 :(得分:1)

查看UIScrollViewDelegate

https://developer.apple.com/library/ios/documentation/uikit/reference/uiscrollviewdelegate_protocol/reference/uiscrollviewdelegate.html

<强>更新

以下是一个例子:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    float scrollViewHeight = scrollView.frame.size.height;
    float scrollContentSizeHeight = scrollView.contentSize.height;
    float scrollOffset = scrollView.contentOffset.y;

    if (scrollOffset == 0)
    {
        // then we are at the top
    }
    else if (scrollOffset + scrollViewHeight == scrollContentSizeHeight)
    {
        // then we are at the end
    }
}