iphone - 如何获取键盘大小以调整 UITextView 的大小以及如何在日文键盘上使用 UIKeyboardFrameEndUserInfoKey?

标签 iphone ios keyboard uitextview

如何获取键盘大小以调整 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];
}

非常感谢您的帮助!

最佳答案

正确的代码片段:

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?

关于iphone - 如何获取键盘大小以调整 UITextView 的大小以及如何在日文键盘上使用 UIKeyboardFrameEndUserInfoKey?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8540803/

相关文章:

iphone - 用于 Objective-C 的 OPC DA 客户端库

iphone - iOS 4.2 上有哪些字体可用?

iphone - ASIHTTPRequest 错误消息 - 初学者

ios - Stelford Titanium Calendar 未在 ios 上向 ical 添加事件

ios - 将图像添加到 uitableview 单元格

iphone - 如何在 Ionic 3 中隐藏键盘?

ios - 从昨天开始无法将存档上传到应用商店

ios - 使用 API 中的坐标绘制路线

cordova - ionic Cordova 键盘将 ionic 页脚栏推离屏幕

ios - 如何从应用程序设置中的文本字段中退出键盘