【问题标题】:How to stop a UIScrollView from scrolling when it reaches the bottom如何在 UIScrollView 到达底部时停止滚动
【发布时间】:2015-05-15 05:53:30
【问题描述】:

当 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];

然后滚动回到底部。

有没有办法让它保持在底部而不会“反弹”,就像一旦它触到底部,就停止移动。

谢谢。

【问题讨论】:

  • 您可能需要使用- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset 而不是scrollViewDidEndDecelerating:

标签: ios objective-c ios8 uiscrollview setcontentview


【解决方案1】:

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

【讨论】:

  • scrollView.bounces = NO;是我想要的。起初在属性列表中没有看到它
  • @Ritu 能否告诉我如何截取 IB 的屏幕截图。
  • @AshokLondhe 在 Mac 上,要截屏,请按住 Shift+Option+4。它将显示一个焦点指针。现在拖动鼠标选择要截图的区域
  • @Ritu 非常感谢。
【解决方案2】:

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

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

【讨论】:

    【解决方案3】:

    反弹问题,你可以解决

      var progressScrollView = UIScrollView()
      progressScrollView.bounces = false
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-25
      • 2019-10-05
      • 1970-01-01
      • 1970-01-01
      • 2021-06-27
      • 2012-09-25
      相关资源
      最近更新 更多