iOS|iOS 获取键盘高度

- (void) registerForKeyboardNotifications{

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasHidden:) name:UIKeyboardDidHideNotification object:nil];
}
- (void) keyboardWasShown:(NSNotification *) notif{
NSDictionary *info = [notif userInfo];
NSValue *value = https://www.it610.com/article/[info objectForKey:UIKeyboardBoundsUserInfoKey];
CGSize keyboardSize = [value CGRectValue].size;
CGRect scrollViewFrame= [scrollView frame];
scrollViewFrame.size.height -= keyboardSize.height;
scrollView.frame = scrollViewFrame;
[scrollView scrollRectToVisible:inputElementFrame animated:YES];
keyboardWasShown = YES;
}
- (void) keyboardWasHidden:(NSNotification *) notif{
NSDictionary *info = [notif userInfo];
NSValue *value = https://www.it610.com/article/[info objectForKey:UIKeyboardBoundsUserInfoKey];
CGSize keyboardSize = [value CGRectValue].size;
CGRect scrollViewFrame= [scrollView frame];
scrollViewFrame.size.height += keyboardSize.height;
scrollView.frame = scrollViewFrame;
【iOS|iOS 获取键盘高度】keyboardWasShown = NO;
}

    推荐阅读