且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检查 UIScrollView 是否到达顶部或底部

更新时间:2023-11-02 17:22:16

在你的类中实现UIScrollViewDelegate,然后添加:

Implement the UIScrollViewDelegate in your class, and then add this:

-(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
    }
}

希望这就是你所追求的!否则,通过在上面的代码中添加更多条件和 NSLog 滚动偏移的值来进行修补.

Hope this is what you are after! Else have a tinker by adding more conditions to the above code and NSLog the value of scrollOffset.