本文共 1113 字,大约阅读时间需要 3 分钟。
- - (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;
- }
转载于:https://www.cnblogs.com/fengmin/p/5015854.html