首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带UITableView的ios UITableView

带UITableView的ios UITableView
EN

Stack Overflow用户
提问于 2014-09-11 07:26:18
回答 1查看 76关注 0票数 0

在我的代码中,每当键盘弹出时,tableView就会向上推,这样我就可以看到tableView的底部。但是最前面的三四个细胞会藏在视图后面。当键盘关闭时,scrollView的顶部似乎被切断了。

当我发短信时,我如何保持我的桌面视图完整查看?

这是我的密码。

代码语言:javascript
复制
-(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;
  }];
}

将文本添加到单元格后滚动到底部。

代码语言:javascript
复制
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];
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-09-11 11:20:20

与其在键盘显示时转换视图,不如通过调整其框架来缩小视图:

代码语言:javascript
复制
CGRect newFrame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height-deltaY);
self.view.frame = newFrame; 
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25781522

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档