如何使tableView自动滚动到顶部/底部? [英] How to make tableView Scroll Automatically to top/bottom?
问题描述
这只是一个测试,我可以将它添加到应用程序。嗯....我有一个 tableView
。
-
如果点击
button1
,我想让tableView自动向上滚动到顶部。 -
如果我点击
button2
,我想让tableView自动向下滚动到底部。
如何做到这一点?你还可以看看滚动视图的 setContentOffset:animated:
code>方法。
转到页首意味着
[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:
的唯一问题是当设置节和表标题时可能不会有帮助。
This is just a test, which i might add it to the app. Well.... I have a tableView
.
If click
button1
, I want the tableView to scroll up automatically to the top.If I click
button2
I want the tableView to scroll down automatically to the bottom.
How can this be done ? What about Scroll Speed ?
You can also look at the scroll view's setContentOffset:animated:
method.
Going to the top would mean,
[self.tableView setContentOffset:CGPointZero animated:YES];
and the bottom would be,
CGFloat height = self.tableView.contentSize.height - self.tableView.bounds.size.height;
[self.tableView setContentOffset:CGPointMake(0, height) animated:YES];
You won't have control over the animation duration.
The only problem with scrollToRowAtIndexPath:atScrollPosition:animated:
is that it might not be helpful when section and table headers are set.
这篇关于如何使tableView自动滚动到顶部/底部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!