本文介绍了如何获得键盘大小来调整UITextView的大小以及如何在日语键盘上使用UIKeyboardFrameEndUserInfoKey?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何让键盘大小调整大小 UITextView
以及如何使用日语键盘使用 UIKeyboardFrameEndUserInfoKey
?以下用于调整 UITextView
的代码在标准键盘上运行良好。但不适合日本人。如何解决?
How to get a keyboard size to resize UITextView
and how to use UIKeyboardFrameEndUserInfoKey
with Japanese keyboard? The following code to resize UITextView
works good on a standard keyboard. But doesn't work with 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];
}
非常感谢您的帮助!
推荐答案
代码的正确片段:
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!
该方法已过时。正确答案位于:
这篇关于如何获得键盘大小来调整UITextView的大小以及如何在日语键盘上使用UIKeyboardFrameEndUserInfoKey?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!