动态获取键盘边框

时间:2023-01-30
本文介绍了动态获取键盘边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

是否可以动态获取键盘的框架,实际上是它的高度?由于我有一个 UITextView 并且我想在更改键盘输入法时根据键盘框架高度调整其高度.如您所知,不同的输入法可能有不同的键盘框架高度.

Is it possible to get the frame, actually its height, of the keyboard dynamically? As I have a UITextView and I would like to adjust its height according to the keyboard frame height, when the input method of the keyboard is changed. As you know, different input methods may have different keyboard frame height.

推荐答案

试试这个:

[[NSNotificationCenter defaultCenter] addObserver:self
                                     selector:@selector(keyboardWasShown:)
                                         name:UIKeyboardDidShowNotification
                                       object:nil];

- (void)keyboardWasShown:(NSNotification *)notification
{

// Get the size of the keyboard.
CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;

//Given size may not account for screen rotation
int height = MIN(keyboardSize.height,keyboardSize.width);
int width = MAX(keyboardSize.height,keyboardSize.width);

//your other code here..........
}

教程了解更多信息

这篇关于动态获取键盘边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:以编程方式更改android设备的输入法 下一篇:iphone UISearchBar 完成按钮始终启用

相关文章

最新文章