阅读262 返回首页    go 阿里云 go 技术社区[云栖]


如何在键盘出现时滚动表格,以适应输入框的显示

//
- (void)registerForKeyboardNotifications {
  [[NSNotificationCenter defaultCenter] addObserver:self
                                           selector:@selector(keyboardWillShow:)
                                               name:UIKeyboardWillShowNotification
                                             object:nil];
  
  [[NSNotificationCenter defaultCenter] addObserver:self
                                           selector:@selector(keyboardWillHide:)
                                               name:UIKeyboardWillHideNotification
                                             object:nil];
  return;
}

- (void)keyboardWillShow:(NSNotification *) notif {
  NSDictionary *info = [notif userInfo];
  NSValue *value = [info objectForKey:UIKeyboardFrameBeginUserInfoKey];
  CGSize keyboardSize = [value CGRectValue].size;
  [_tableView setContentOffset:CGPointMake(_tableView.contentOffset.x,
                                           _tableView.contentOffset.y + keyboardSize.height + 10)
                      animated:YES];
  return;
}

- (void)keyboardWillHide:(NSNotification *) notif {
  NSDictionary *info = [notif userInfo];
  NSValue *value = [info objectForKey:UIKeyboardFrameBeginUserInfoKey];
  CGSize keyboardSize = [value CGRectValue].size;
  [_tableView setContentOffset:CGPointMake(_tableView.contentOffset.x,
                                           _tableView.contentOffset.y - keyboardSize.height - 10)
                      animated:YES];
  return;
}

最后更新:2017-04-03 12:55:46

  上一篇:go Spark SQL组件源码分析
  下一篇:go 小谈Android应用的电量消耗和优化策略