UIScrollView仅在底部禁用垂直反弹 [英] UIScrollView disable vertical bounce only at bottom

查看:187
本文介绍了UIScrollView仅在底部禁用垂直反弹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一种方法来禁用UIScrollView的垂直反弹但仅限于底部。我仍然需要在顶部反弹。

I've been searching for a way to disable vertical bounce for a UIScrollView but only at bottom. I still need to have the bounce at the top.

找不到任何东西。这可能吗?

Couldn't find anything. Is this possible?

提前致谢!

推荐答案

使用UIScrollViewDelegate方法 scrollViewDidScroll 检查scrollview的内容偏移量,或多或少检查用户是否正在尝试滚动超出滚动视图的底部边界。然后使用它将滚动设置回滚动视图的末尾。它发生得如此之快,以至于你根本无法判断滚动视图是否反弹或超出其范围。

Use the UIScrollViewDelegate method scrollViewDidScroll to check the content offset of the scrollview and more or less check if the user is trying to scroll beyond the bottom bounds of the scroll view. Then just use this to set the scroll back to the end of the scroll view. It happens so rapidly that you can't even tell that the scroll view bounced or extended beyond its bounds at all.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView.contentOffset.y >= scrollView.contentSize.height - scrollView.frame.size.height) {
        [scrollView setContentOffset:CGPointMake(scrollView.contentOffset.x, scrollView.contentSize.height - scrollView.frame.size.height)];
    }
}

这篇关于UIScrollView仅在底部禁用垂直反弹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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