简体   繁体   English

如何获得键盘大小来调整UITextView的大小以及如何在日语键盘上使用UIKeyboardFrameEndUserInfoKey?

[英]How to get keyboard size to resize UITextView and how to use UIKeyboardFrameEndUserInfoKey with Japanese keyboard?

How to get a keyboard size to resize UITextView and how to use UIKeyboardFrameEndUserInfoKey with Japanese keyboard? 如何获得键盘大小来调整UITextView大小以及如何在日语键盘上使用UIKeyboardFrameEndUserInfoKey The following code to resize UITextView works good on a standard keyboard. 以下用于调整UITextView大小的代码在标准键盘上运行良好。 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];
}

Thanks a lot for the help! 非常感谢您的帮助!

The correct fragment of the code: 代码的正确片段:

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! WARNIGN!

The method is obsolete. 该方法已过时。 The correct answer is located here: How can I add support for Chinese keyboard with UITextView on iOS 7? 正确答案位于: 如何在iOS 7上使用UITextView添加对中文键盘的支持?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM