释放双眼,带上耳机,听听看~!
1.注册检测键盘的通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardWillShowNotification object:nil];
//注册键盘隐藏通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector (keyboardHide:) name: UIKeyboardWillHideNotification object:nil];
2.键盘出现的函数
#pragma mark - 键盘出现函数
- (void)keyboardWasShown:(NSNotification *)notif
{
NSDictionary *info = [notif userInfo];
NSValue *value = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
CGSize keyboardSize = [value CGRectValue].size;
_keyboardSize = keyboardSize.height;
}
3.键盘隐藏的函数
#pragma mark - 键盘关闭函数
-(void)keyboardHide:(NSNotification *)notif
{
NSDictionary *info = [notif userInfo];
NSValue *value = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
CGSize keyboardSize = [value CGRectValue].size;
_keyboardSize = keyboardSize.height;
}