2011-01-08 25 views
4

我需要知道当前的键盘类型。我正在设置一个实例变量iPhone SDK:如何确定UIKeyboardDidShowNotification中的键盘类型?

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField 

但是,测试表明,由于通知的异步性质,这并不总是可靠的。

我想知道的是,如果有人能告诉我如何确定 中的当前键盘类型的通知?

- (void)keyboardDidShow:(NSNotification *) { 
    // Need way to determine keyboard type here 
    } 

谢谢。

回答

4

如果你问的是键盘的语言只能在iOS4.2的和上面使用UITextInputMode class方法来完成:+[UITextInputMode currentInputMode];

如果你想要的大小(因为根据语言的大小可以改变)很容易,从关键的UI对象获取大小UIKeyboardBoundsUserInfoKey

- (void)keyboardWasShown:(NSNotification*)aNotification{ 
NSDictionary* info = [aNotification userInfo]; 
NSValue* aValue = [info UIKeyboardFrameEndUserInfoKey]; 
CGSize keyboardSize = [aValue CGRectValue].size; 
//I just got the size! ... do something with it 
} 
+0

我需要知道UIKeyboardTypeNumberPad是否为true。你知道这些信息是否在notification.userInfo中可用?我无法从文档中看出来,并在编译时收到警告。 – 2011-01-08 18:37:21