在viewDidLoad里注冊通知失晴,監(jiān)聽鍵盤變化
- (void)viewDidLoad
{
[super viewDidLoad];
//增加監(jiān)聽褪那,當鍵盤出現(xiàn)或改變時收出消息
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
//增加監(jiān)聽,當鍵退出時收出消息
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
}
//當鍵盤出現(xiàn)或改變時調(diào)用
- (void)keyboardWillShow:(NSNotification *)aNotification
{
//獲取鍵盤的高度
NSDictionary *userInfo = [aNotification userInfo];
NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
CGRect keyboardRect = [aValue CGRectValue];
int height = keyboardRect.size.height;
}
//當鍵退出時調(diào)用
- (void)keyboardWillHide:(NSNotification *)aNotification
{
}