How to get keyboard size for resizing UITextView and how to use UIKeyboardFrameEndUserInfoKey with japanese keyboard?

How to get keyboard size for resizing UITextView and how to use UIKeyboardFrameEndUserInfoKey with UIKeyboardFrameEndUserInfoKey keyboard? The following code for resizing UITextView works great on a standard keyboard. But does not work with the Japanese. How to fix it?

 - (void)keyboardWillShow:(NSNotification *)aNotification { [self moveTextViewForKeyboard:aNotification up:YES]; } - (void)keyboardWillHide:(NSNotification *)aNotification { [self moveTextViewForKeyboard:aNotification up:NO]; } - (void) moveTextViewForKeyboard:(NSNotification*)aNotification up: (BOOL) up { NSDictionary* userInfo = [aNotification userInfo]; // Get animation info from userInfo NSTimeInterval animationDuration; UIViewAnimationCurve animationCurve; CGRect keyboardEndFrame; [[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&animationCurve]; [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:&animationDuration]; [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardEndFrame]; // Animate up or down [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:animationDuration]; [UIView setAnimationCurve:animationCurve]; CGRect newFrame = textView.frame; CGRect keyboardFrame = [self.view convertRect:keyboardEndFrame toView:nil]; newFrame.size.height -= keyboardFrame.size.height * (up? 1 : -1); textView.frame = newFrame; [UIView commitAnimations]; } 

Many thanks for the help!

+6
source share
1 answer

Correct code snippet:

 CGRect newFrame = editSource.frame; CGRect keyboardFrame = [self.view convertRect:keyboardEndFrame toView:nil]; keyboardFrame.size.height -= tabBarController.tabBar.frame.size.height; if (up) { editHeight = newFrame.size.height; newFrame.size.height -= keyboardFrame.size.height; } else { newFrame.size.height = editHeight; } editSource.frame = newFrame; 

WARNIGN!

The method is deprecated. The correct answer is here: How to add Chinese keyboard support from UITextView on iOS 7?

+6
source

Source: https://habr.com/ru/post/903955/


All Articles