监听 键盘

2017-08-17  本文已影响0人  奕珃

//注册键盘出现的通知

[[NSNotificationCenter defaultCenter]addObserver:self

selector:@selector(keyboardWasShown:)

name:UIKeyboardWillShowNotification object:nil];

//注册键盘消失的通知

[[NSNotificationCenterdefaultCenter]addObserver:self

selector:@selector(keyboardWillBeHidden:)

name:UIKeyboardWillHideNotification object:nil];

//键盘出来时的操作

- (void)keyboardWasShown:(NSNotification*)aNotification

{

//键盘高度

CGRect keyBoardFrame = [[[aNotification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue];

}

//键盘消失时的操作

-(void)keyboardWillBeHidden:(NSNotification*)aNotification

{

}

记得最后要删除监听 

- (void)dealloc {

[[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillShowNotification object:nil];

[[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillHideNotification object:nil];

}

上一篇 下一篇

猜你喜欢

热点阅读