如何让tableView的偏移量变为零?
我有一个 TableView,有很多 TableViewCell,但是在 TableView 的最后我想编写一个代码,使 tableview 偏移量变为零,这样 tableview 就会回到顶部,
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
if (scrollView.contentOffset.y <=-30) {
[self dosomething];
}
else if(scrollView.contentOffset.y >=1150){
[tableViewA setContentOffset:CGPointZero animated:YES];//this code is called and yet offset doesn't become 0
}
}
所以使用这段代码,如果用户弹到顶部,它会调用 dosomething 函数,如果我们弹到底部,它会在顶部创建一个 tableViewA,但它仍然在底部。如果我没记错的话,tableView会再次弹到底部。任何人都可以给我线索吗?
I have a TableView, that Have so many TableViewCell, but in the end of TableView I want to make a code that will make tableview offset become zero, so the tableview back to the top
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
if (scrollView.contentOffset.y <=-30) {
[self dosomething];
}
else if(scrollView.contentOffset.y >=1150){
[tableViewA setContentOffset:CGPointZero animated:YES];//this code is called and yet offset doesn't become 0
}
}
so with this code, if user bounce to the top, it will call dosomething function, and if we bounce to the bottom, it will make a tableViewA at the top, but it's still at bottom. if I am not wrong, the tableView Bounce again to bottom. any one can give me a clue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我尝试了您的代码,发现 tableview 确实将其 contentOffset 设置为 (0,0) 但它将继续拖动动画。似乎在滚动动画期间,tableview 会同时进行动画处理并更改其边界,以便调用layoutSubviews每次边界发生变化时。因此,即使 contentOffset 设置为 (0,0),但不久之后,边界也设置为新值以继续滚动动画。
也许你可以尝试
I tried your code and find that the tableview did set it's contentOffset to (0,0) but It will continue the drag animation.Seems that during the scroll animation, the tableview animates and changes it's bounds at the same time in order to call layoutSubviews every time the bounds change. So even the contentOffset was set to (0,0) but just after that the bounds was set to a new value to continue the scroll animation.
Maybe you can try