2014-09-04 91 views
2

我正在嘗試在鍵盤即將顯示時收到通知,但目前正在顯示鍵盤後觸發。鍵盤通知沒有正確觸發

這裏是我的通知註冊:

[[NSNotificationCenter defaultCenter] 
    addObserver:self 
    selector:@selector (keyboardDidShow:) 
    name: UIKeyboardDidShowNotification 
    object:nil]; 
[[NSNotificationCenter defaultCenter] 
    addObserver:self 
    selector:@selector (keyboardDidHide:) 
    name: UIKeyboardDidHideNotification 
    object:nil]; 

回答

1

嘗試使用這樣的:

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

更改UIKeyboardDidShowNotificationUIKeyboardWillShowNotification