【问题标题】:How to get keyboard size to resize UITextView and how to use UIKeyboardFrameEndUserInfoKey with Japanese keyboard?如何获取键盘大小以调整 UITextView 的大小以及如何将 UIKeyboardFrameEndUserInfoKey 与日文键盘一起使用?
【发布时间】:2012-01-22 08:55:03
【问题描述】:

如何获得键盘大小以调整UITextView 的大小以及如何将UIKeyboardFrameEndUserInfoKey 与日文键盘一起使用?以下用于调整UITextView 大小的代码在标准键盘上运行良好。但不适用于日语。如何解决?

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

非常感谢您的帮助!

【问题讨论】:

    标签: iphone ios keyboard uitextview


    【解决方案1】:

    正确的代码片段:

    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;
    

    警告!

    该方法已过时。正确答案在这里:How can I add support for Chinese keyboard with UITextView on iOS 7?

    【讨论】:

    • 这个方法至少在 iOS 7 上不能正常工作。
    猜你喜欢
    • 1970-01-01
    • 2011-11-26
    • 2011-11-02
    • 1970-01-01
    • 2015-11-12
    • 1970-01-01
    • 1970-01-01
    • 2017-05-03
    相关资源
    最近更新 更多