2013-04-24 15 views
1

之前,我想要得到的鍵盤的大小,我這樣做如下:要獲得鍵盤的大小,它表明

- (void)viewDidLoad 
{ 
    .... 

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; 

    .... 
} 

//I can get the size here 
- (void)keyboardWillShow:(NSNotification *)notification 
{ 

    NSDictionary *userInfo = [notification userInfo]; 
    NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey]; 
    CGRect keyboardRect = [aValue CGRectValue]; 
} 

但現在,我想鍵盤之前得到大小(在調用「keyboardWillShow」方法之前)。我該怎麼做?

+0

檢查此鏈接:http://stackoverflow.com/questions/4213878/what-is-the-height-of-ipads-onscreen-keyboard – Amit 2013-04-24 06:47:49

回答

0

正如您從答案here之一看到的,它確實取決於鍵盤的類型以及您所在的設備。您還應該記住,將來鍵盤可能會發生變化,因此您應該依靠在NSNotification上傳遞的字典來確定它的確切大小。

1

其實- (void)keyboardWillShow:(NSNotification *)notification;方法在鍵盤顯示前被解僱。