UIScrollView disable vertical bounce only at bottom

后端 未结 7 626
被撕碎了的回忆
被撕碎了的回忆 2020-12-29 04:26

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.

相关标签:
7条回答
  • 2020-12-29 05:15

    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)];
        }
    }
    
    0 讨论(0)
提交回复
热议问题