iPhone - 知道UIScrollView是否达到顶部或底部 [英] iPhone - knowing if a UIScrollView reached the top or bottom

查看:222
本文介绍了iPhone - 知道UIScrollView是否达到顶部或底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法知道 UIScrollView 是否已达到顶部或底部

Is there a way to know if a UIScrollView has reached the top or bottom inside

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView 
                  willDecelerate:(BOOL)decelerate

谢谢。

推荐答案

实施您班级中的 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值为scrollOffset。

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.

这篇关于iPhone - 知道UIScrollView是否达到顶部或底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆