如何在 UIScrollView 到达底部时停止滚动

How to stop a UIScrollView from scrolling when it reaches the bottom

我有以下代码可以在 UIScrollView 到达其内容视图的末尾时获取事件:

- (void) scrollViewDidEndDecelerating:(UIScrollView *) scrollView
{
    float currentEndPoint = scrollView.contentOffset.y + scrollView.frame.size.height;

    // CGPoint bottomOffset = CGPointMake(0, scrollView.contentSize.height - scrollView.bounds.size.height);
    // [scrollView setContentOffset:bottomOffset animated:NO];

    if (currentEndPoint >= scrollView.contentSize.height)
    {
        // We are at the bottom

我注意到,当我滚动到底部时,它会碰到它并弹回。

如果我添加这个:

CGPoint bottomOffset = CGPointMake(0, scrollView.contentSize.height - scrollView.bounds.size.height);
[scrollView setContentOffset:bottomOffset animated:NO];

然后卷轴回到底部。

有没有办法让它在没有"bounce back up"的情况下留在底部,一旦它触底,就停止移动。

谢谢。

您应该取消选中滚动视图的反弹 属性。查看屏幕截图!

我不太明白你的意思,我知道你想在 table 视图到达底部时停止滚动。所以这是过程:-

- (void) scrollViewDidEndDecelerating:(UIScrollView *) scrollView
{
    float currentEndPoint = scrollView.contentOffset.y + scrollView.frame.size.height;

    if (currentEndPoint >= scrollView.contentSize.height)
    {

    CGPoint offset = scrollView.contentOffset;
    offset.x -= 1.0;
    offset.y -= 1.0;
    [scrollView setContentOffset:offset animated:NO];
    offset.x += 1.0;
    offset.y += 1.0;
    [scrollView setContentOffset:offset animated:NO];
  }
}

反弹问题,你可以通过

解决
  var progressScrollView = UIScrollView()
  progressScrollView.bounces = false