简体   繁体   English

UITableView beginUpdates endUpdates滚动到单元格顶部

[英]UITableView beginUpdates endUpdates scrolls to the top of cell

This is what I am doing so as to set the focus on the same point after UITableView beginUpdates : 我这样做是为了将焦点放在UITableView beginUpdates之后的同一点上:

CGPoint offset = tableMessageDetail.contentOffset;
// CGPoint textPoint = [self.view convertPoint:cell.txtReply.frame.origin toView:nil];
[tableMessageDetail beginUpdates];
[tableMessageDetail endUpdates];
[tableMessageDetail setContentOffset:offset animated:NO];
//[tableMessageDetail scrollRectToVisible:CGRectMake(cell.frame.origin.x, cell.frame.origin.y, cell.frame.size.width, cell.frame.size.height) animated:YES];  

But the position after endUpdates , when the cell is too high, comes to the top of cell. 但是,当单元格太高时, endUpdates之后的位置将到达单元格的顶部。 I have tried with the commented approach as well, but that too is not perfect. 我也尝试过使用评论的方法,但这也不是完美的。

Giving a thought, hope this helps: Remove all animations on the tableView's layer before setting the contentOffset. 提出一个想法,希望对您有所帮助:在设置contentOffset之前,删除tableView图层上的所有动画。

[tableView.layer removeAllAnimations];
[tableView setContentOffset:offset animated:NO];

and then, 接着,

[tableView scrollToRowAtIndexPath:cell.indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];

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

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