【发布时间】:2014-09-13 02:18:06
【问题描述】:
在我的代码中,每次弹出键盘时,tableView 都会向上推,所以我可以看到 tableView 的底部。但是前三个或四个单元格将隐藏在视图后面。键盘退出时,scrollView 的顶部似乎被剪切了。
我怎样才能让我的表格视图在发短信时完整查看?
这是我的代码...
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardHide:) name:UIKeyboardWillHideNotification object:nil];
}
-(void)keyboardShow:(NSNotification *)note{
CGRect keyBoardRect=[note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGFloat deltaY=keyBoardRect.size.height;
[UIView animateWithDuration:[note.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue] animations:^{
self.view.transform=CGAffineTransformMakeTranslation(0, -deltaY);
}];
}
-(void)keyboardHide:(NSNotification *)note{
[UIView animateWithDuration:[note.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue] animations:^{
self.view.transform = CGAffineTransformIdentity;
}];
}
向单元格添加文本后滚动到底部。
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:(self.data.count-1) inSection:0];
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationRight];
[self.tableView endUpdates];
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
【问题讨论】:
标签: ios uitableview keyboard