NSNotificationCenter監聽鍵盤彈起和隱藏事件

        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:方法中對控件的高度進行處理。。。大笑


發佈了29 篇原創文章 · 獲贊 0 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章