如何获取键盘大小以调整 UITextView 的大小以及如何将 UIKeyboardFrameEndUserInfoKe

How to get keyboard size to resize UITextView and how to use UIKeyboardFrameEndUserInfoKey with Japanese keyboard?(如何获取键盘大小以调整 UITextView 的大小以及如何将 UIKeyboardFrameEndUserInfoKey 与日文键盘一起使用?) - IT屋-程序员软件开发技
本文介绍了如何获取键盘大小以调整 UITextView 的大小以及如何将 UIKeyboardFrameEndUserInfoKey 与日文键盘一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

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

How to get a keyboard size to resize UITextView and how to use UIKeyboardFrameEndUserInfoKey with Japanese keyboard? The following code to resize UITextView works good on a standard keyboard. 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];
}

非常感谢您的帮助!

推荐答案

正确的代码片段:

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;

警告!

该方法已过时.正确答案在这里:如何在 iOS 7 上通过 UITextView 添加对中文键盘的支持?

这篇关于如何获取键盘大小以调整 UITextView 的大小以及如何将 UIKeyboardFrameEndUserInfoKey 与日文键盘一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Pywin32 (com objects) on Mac(Mac 上的 Pywin32(com 对象))
convert big yml data(转换大 yml 数据)
Is there a native YAML library for iPhone?(是否有适用于 iPhone 的本机 YAML 库?)
View aligned to top of keyboard appears in wrong place in iOS 9 Shortcut Bar only mode(在 iOS 9 Shortcut Bar only 模式下,与键盘顶部对齐的视图出现在错误的位置)
Disable speech to text button (Micro phone) on soft input keyboard in android programmatically(以编程方式在android中的软输入键盘上禁用语音到文本按钮(麦克风))
UIkeyboard type(UI键盘类型)