如何在iOS 7上使用UITextView添加对中文键盘的支持? [英] How can I add support for Chinese keyboard with UITextView on iOS 7?
本文介绍了如何在iOS 7上使用UITextView添加对中文键盘的支持?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 iOS 7 上添加 UITextView
的中文键盘支持?目前我正在使用以下代码。但它只适用于标准尺寸的键盘。它只为主键盘调整 UITextView
的大小而没有额外的中文面板。
How can I add support for Chinese keyboard with UITextView
on iOS 7? Currently I'm using the following code. But it works correctly only for standard-sized keyboards. It resizes UITextView
only for the main keyboard without additional Chinese panel.
bool keyboardIsShown;
float keyboardDelta;
- (void)keyboardWillShow:(NSNotification*)aNotification {
if (!keyboardIsShown) {
keyboardIsShown = true;
NSDictionary* userInfo = [aNotification userInfo];
CGSize keyboardSize = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
if (is_Landscape) {
keyboardSize = CGSizeMake(keyboardSize.height, keyboardSize.width);
}
keyboardSize.height -= tabBarController.tabBar.frame.size.height;
CGRect viewFrame = myUITextView.frame;
keyboardDelta = keyboardSize.height;
viewFrame.size.height -= keyboardDelta;
NSTimeInterval animationDuration;
UIViewAnimationCurve animationCurve;
[[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&animationCurve];
[[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:&animationDuration];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:animationCurve];
[UIView setAnimationDuration:animationDuration];
[myUITextView setFrame:viewFrame];
[UIView commitAnimations];
}
}
- (void)keyboardWillHide:(NSNotification*)aNotification {
keyboardIsShown = false;
CGRect viewFrame = editor.frame;
viewFrame.size.height += keyboardDelta;
NSDictionary* userInfo = [aNotification userInfo];
NSTimeInterval animationDuration;
UIViewAnimationCurve animationCurve;
[[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&animationCurve];
[[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:&animationDuration];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:animationCurve];
[UIView setAnimationDuration:animationDuration];
[myUITextView setFrame:viewFrame];
[UIView commitAnimations];
}
推荐答案
感谢 jcaron 即可。正确的代码:
Thanks to jcaron. The correct code:
bool keyboardIsShown;
float editorHeight;
- (void)keyboardWillShow:(NSNotification*)aNotification {
NSDictionary* userInfo = [aNotification userInfo];
CGSize keyboardSize = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
if (is_Landscape) {
keyboardSize = CGSizeMake(keyboardSize.height, keyboardSize.width);
}
keyboardSize.height -= tabBarController.tabBar.frame.size.height;
CGRect viewFrame = editor.frame;
if (!keyboardIsShown) {
editorHeight = viewFrame.size.height;
}
viewFrame.size.height = editorHeight - keyboardSize.height;
keyboardIsShown = true;
NSTimeInterval animationDuration;
UIViewAnimationCurve animationCurve;
[[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&animationCurve];
[[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:&animationDuration];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:animationCurve];
[UIView setAnimationDuration:animationDuration];
[editor setFrame:viewFrame];
[UIView commitAnimations];
}
- (void)keyboardWillHide:(NSNotification*)aNotification {
keyboardIsShown = false;
CGRect viewFrame = editor.frame;
viewFrame.size.height = editorHeight;
NSDictionary* userInfo = [aNotification userInfo];
NSTimeInterval animationDuration;
UIViewAnimationCurve animationCurve;
[[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&animationCurve];
[[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:&animationDuration];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:animationCurve];
[UIView setAnimationDuration:animationDuration];
[editor setFrame:viewFrame];
[UIView commitAnimations];
}
这篇关于如何在iOS 7上使用UITextView添加对中文键盘的支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文