2025-06-14

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;

}

 

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *