今天的問(wèn)題如標(biāo)題所說(shuō)宝当,這個(gè)操作的使用場(chǎng)景就是我們平常看到的聊天框發(fā)消息啊,發(fā)完消息之后UITableView
滾動(dòng)到底部拳魁,我們先看看效果圖
解決:上代碼
[UIView animateWithDuration:0 animations:^{
[self.tableView reloadData];
[self.tableView layoutIfNeeded];
} completion:^(BOOL finished) {
if (self.tableView.contentSize.height > self.tableView.bounds.size.height) {
[self.tableView setContentOffset:CGPointMake(0, self.tableView.contentSize.height-self.tableView.bounds.size.height) animated:YES];
}
}];
網(wǎng)上也看過(guò)別人分享的方法乘客,但是都不是我想要的效果狐血,最后我用這段代碼代碼達(dá)到了效果,
-
[self.tableView layoutIfNeeded]
易核,因?yàn)槲沂褂昧?code>Masonry布局匈织,所以需要執(zhí)行這行代碼之后再滾動(dòng)
結(jié)束啦??