如何在iOS 7上添加对UITextView的中文键盘支持?

如何在iOS 7上添加对UITextView中文键盘支持? 目前我正在使用下面的代码。 但只适用于标准尺寸的键盘。 它只调整UITextView的主键盘而不需要额外的中文面板。

 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 。 正确的代码:

 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]; }