关于iOS 输入法的一些问题
1、判断输入法是中文还是英文
ios5上但切换到中文输入法的时候,在键盘上面会多出一条汉字选择的区域,
因为需要根据虚拟键盘的高度调整界面元素的位置,
查了API说UITextInputMode 可以检测到输入法改变的事件,遗憾的是实际上是
不起作用de 。最后找到一种解决的方法是监听键盘显示的事件,有点怪异哦。
输入模式变的时候,键盘的高度改变了,会发送个UIKeyboardDidShowNotification
消息。
#define KEYBOARD_HEIGHT 216
//chinese input mode under ios5
#define KEYBOARD__IOS5_HEIGHT 252
- (void)keyboardWasShown:(NSNotification*)aNotification //代理方法
{
NSDictionary* info = [aNotification userInfo];
//get keyboard size
CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
//adjust ui elements postition here
if (kbSize.height == KEYBOARD_HEIGHT)
{
}
else if(kbSize.height == KEYBOARD__IOS5_HEIGHT)
{
}
}
- (void)viewDidLoad
{
[superviewDidLoad];
//register UIKeyboardDidShowNotification,
//off course you should unregister the notification somewhere
[[NSNotificationCenterdefaultCenter] addObserver:self
selector:@selector(keyboardWasShown:)
name:UIKeyboardDidShowNotificationobject:nil]; //注册监听键盘输入法的消息
}