首页 > 其他 > 详细

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

时间:2015-12-03 13:50:34      阅读:278      评论:0      收藏:0      [点我收藏+]
  1. //  
  2. - (void)registerForKeyboardNotifications {  
  3.   [[NSNotificationCenter defaultCenter] addObserver:self  
  4.                                            selector:@selector(keyboardWillShow:)  
  5.                                                name:UIKeyboardWillShowNotification  
  6.                                              object:nil];  
  7.     
  8.   [[NSNotificationCenter defaultCenter] addObserver:self  
  9.                                            selector:@selector(keyboardWillHide:)  
  10.                                                name:UIKeyboardWillHideNotification  
  11.                                              object:nil];  
  12.   return;  
  13. }  
  14.   
  15. - (void)keyboardWillShow:(NSNotification *) notif {  
  16.   NSDictionary *info = [notif userInfo];  
  17.   NSValue *value = [info objectForKey:UIKeyboardFrameBeginUserInfoKey];  
  18.   CGSize keyboardSize = [value CGRectValue].size;  
  19.   [_tableView setContentOffset:CGPointMake(_tableView.contentOffset.x,  
  20.                                            _tableView.contentOffset.y + keyboardSize.height + 10)  
  21.                       animated:YES];  
  22.   return;  
  23. }  
  24.   
  25. - (void)keyboardWillHide:(NSNotification *) notif {  
  26.   NSDictionary *info = [notif userInfo];  
  27.   NSValue *value = [info objectForKey:UIKeyboardFrameBeginUserInfoKey];  
  28.   CGSize keyboardSize = [value CGRectValue].size;  
  29.   [_tableView setContentOffset:CGPointMake(_tableView.contentOffset.x,  
  30.                                            _tableView.contentOffset.y - keyboardSize.height - 10)  
  31.                       animated:YES];  
  32.   return;  
  33. }  

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

原文:http://www.cnblogs.com/fengmin/p/5015854.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!