iOS成長之路-獲取系統鍵盤的高度 – iPhone手機開發技術文章 iPhone軟體開發教學課程

print?NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];  

    //UIKeyboardWillShowNotification鍵盤出現   

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

  

    //UIKeyboardWillHideNotification 鍵盤隱藏   

    [defaultCenter addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];  

  

– (void)keyboardWillShow:(NSNotification *)aNotification  

{  

    //獲取鍵盤的高度   

    NSDictionary *userInfo = [aNotification userInfo];  

    NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];  

    CGRect keyboardRect = [aValue CGRectValue];  

    int height = keyboardRect.size.width;  

}  

 

NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];

    //UIKeyboardWillShowNotification鍵盤出現

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

 

    //UIKeyboardWillHideNotification 鍵盤隱藏

    [defaultCenter addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];

 

– (void)keyboardWillShow:(NSNotification *)aNotification

{

    //獲取鍵盤的高度

NSDictionary *userInfo = [aNotification userInfo];

    NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];

    CGRect keyboardRect = [aValue CGRectValue];

    int height = keyboardRect.size.width;

}

 

You May Also Like