【问题标题】:How to make tableView Scroll Automatically to top/bottom?如何使 tableView 自动滚动到顶部/底部?
【发布时间】:2011-07-13 17:56:34
【问题描述】:

这只是一个测试,我可能会将它添加到应用程序中。嗯....我有一个tableView。

  1. 如果点击button1,我希望tableView自动向上滚动到顶部。

  2. 如果我点击button2,我希望tableView 自动向下滚动到底部。

如何做到这一点?滚动速度呢?

【问题讨论】:

    标签: iphone objective-c cocoa-touch uitableview scroll


    【解决方案1】:

    你也可以看看滚动视图的setContentOffset:animated:方法。

    登顶意味着,

    [self.tableView setContentOffset:CGPointZero animated:YES];
    

    底部是,

    CGFloat height = self.tableView.contentSize.height - self.tableView.bounds.size.height;
    [self.tableView setContentOffset:CGPointMake(0, height) animated:YES];
    

    您无法控制动画持续时间。

    scrollToRowAtIndexPath:atScrollPosition:animated: 的唯一问题是在设置部分和表格标题时它可能没有帮助。

    【讨论】:

    • "Deepak" - 始终为任何情况提供最佳答案。谢谢大佬。
    • 在表格视图上补偿 contentInset 的最佳方法是什么?
    【解决方案2】:

    scrollToRowAtIndexPath:atScrollPosition:animated:

    滚动接收器,直到由索引路径标识的行位于屏幕上的特定位置。

    - (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-26
      • 2016-11-13
      • 1970-01-01
      相关资源
      最近更新 更多