閱讀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應用的電量消耗和優化策略