NSNotificationCenter真是無所不能,靈活運用NSNotificationCenter能讓一些事情變得簡單。在實際項目開發中,我們有時候在鍵盤彈起進入輸入狀態或者鍵盤隱藏失去焦點的時候需要做一些處理,比如:調整一些控件(輸入框)的高度等。這時候通過NSNotificationCenter來監聽鍵盤彈起和隱藏事件可以讓繁雜的問題變得簡單。
1.監聽鍵盤彈起事件:[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
2.監聽鍵盤隱藏事件:[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keybordWillHiden:) name:UIKeyboardWillHideNotification object:nil];
這樣我們就可以在keyboardWillShow:和keybordWillHiden:方法中對控件的高度進行處理。。。