简体   繁体   English

如何使 tableView 自动滚动到顶部/底部?

[英]How to make tableView Scroll Automatically to top/bottom?

This is just a test, which i might add it to the app.这只是一个测试,我可能会将其添加到应用程序中。 Well.... I have a tableView .嗯....我有一个tableView

  1. If click button1 , I want the tableView to scroll up automatically to the top.如果单击button1 ,我希望 tableView 自动向上滚动到顶部。

  2. If I click button2 I want the tableView to scroll down automatically to the bottom.如果我单击button2 ,我希望 tableView 自动向下滚动到底部。

How can this be done?如何才能做到这一点? What about Scroll Speed?滚动速度呢?

You can also look at the scroll view's setContentOffset:animated: method.您还可以查看滚动视图的setContentOffset:animated:方法。

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.您将无法控制 animation 持续时间。

The only problem with scrollToRowAtIndexPath:atScrollPosition:animated: is that it might not be helpful when section and table headers are set. scrollToRowAtIndexPath:atScrollPosition:animated:的唯一问题是在设置部分和表头时可能没有帮助。

scrollToRowAtIndexPath:atScrollPosition:animated: scrollToRowAtIndexPath:atScrollPosition:动画:

Scrolls the receiver until a row identified by index path is at a particular location on the screen.滚动接收器,直到由索引路径标识的行位于屏幕上的特定位置。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM