1 让tableview 滚动到最底层方法
if (_dataArr.count>0) {
NSIndexPath *ip = [NSIndexPath indexPathForRow:_dataArr.count-1 inSection:0];
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView scrollToRowAtIndexPath:ip atScrollPosition:UITableViewScrollPositionBottom animated:YES];
});
}
2了解scrollview一个方法,用手指滑动才会执行的方法
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
3每次聊天要在最下面加一条数据 使用到的方法(不能用刷新方法加最后一条 得插入)
NSInteger index = self.dataArr.count-1;
NSIndexPath *indexPath=[NSIndexPath indexPathForRow:index inSection:0];
[_tableView insertRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
4 刷新某一条cell方法
NSIndexPath *indexPath=[NSIndexPath indexPathForRow:index inSection:0];
[_tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
5 获取当前tableview 内容高度 有几种方法
(1)获取section的frame
- (CGRect)rectForSection:(NSInteger)section;
(2)获取cell的frame
- (CGRect)rectForRowAtIndexPath:(NSIndexPath *)indexPath;
(3)获取header的frame
- (CGRect)rectForHeaderInSection:(NSInteger)section;
(4)获取footer的frame
- (CGRect)rectForFooterInSection:(NSInteger)section;
***********这里边 我们需求只有一个section 写一个footer 来获取整个当前tableview内容高度
CGRect rectCell = [_tableView rectForFooterInSection:0];
当前内容高度为:rectCell.origin.y
6 以上五部结合一下 弹键盘,适用场景,打一次字,发出去收键盘 ,要是想持续打字键盘不收回去,还需要优化一下下面的方法
- (void)keyboardWillShow:(NSNotification *)notification {
CGRect rect=[notification.userInfo[UIKeyboardFrameEndUserInfoKey]CGRectValue];
WS(weakSelf)
[self.bottomView mas_updateConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.view).offset(-rect.size.height);
}];
if (Height(85)+rect.size.height +weakSelf.contentHeight>kScreenHeight) {
if (weakSelf.contentHeight>kScreenHeight-Height(85)-45) {
[UIView animateWithDuration:0.25 animations:^{
CGRect frame = weakSelf.tableView.frame;
frame.origin.y = - (rect.size.height)+Height(85);
weakSelf.tableView.frame = frame;
}];
[UIView animateWithDuration:0.25 animations:^{
[weakSelf.tableView refreshCurrentTableViewContengHeight];
}];
}else{
[UIView animateWithDuration:0.25 animations:^{
CGRect frame = weakSelf.tableView.frame;
frame.origin.y = - ( Height(85)+rect.size.height +weakSelf.contentHeight)+(kScreenHeight-Height(85))+Height(85)+45;
weakSelf.tableView.frame = frame;
}];
[UIView animateWithDuration:0.25 animations:^{
[weakSelf.tableView refreshCurrentTableViewContengHeight];
}];
}
}
}
- (void)keyboardWillHide:(NSNotification *)notification {
CGFloat tabbarHeight = Height_TabbarSafeBottom;
WS(weakSelf)
[self.bottomView mas_updateConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.view).offset(-tabbarHeight);
}];
[UIView animateWithDuration:0.25 animations:^{
CGRect frame = weakSelf.tableView.frame;
frame.origin.y = Height(85);
weakSelf.tableView.frame = frame;
}];
}