键盘监听事件

//增加监听,当键盘出现或改变时收出消息

[[NSNotificationCenterdefaultCenter]addObserver:self

selector:@selector(keyboardWillShow:)

name:UIKeyboardWillShowNotification

object:nil];

//增加监听,当键盘退出时收出消息

[[NSNotificationCenterdefaultCenter]addObserver:self

selector:@selector(keyboardWillHide:)

name:UIKeyboardWillHideNotification

object:nil];

____________________________________________________________________

//当键盘出现或改变时调用

- (void)keyboardWillShow:(NSNotification*)aNotification

{

//获取键盘的高度

NSDictionary*userInfo = [aNotificationuserInfo];

NSValue*aValue = [userInfoobjectForKey:UIKeyboardFrameEndUserInfoKey];

CGRectkeyboardRect = [aValueCGRectValue];

intheight = keyboardRect.size.height;

if(self.ps.sureNumTF.isEditing) {

self.ps.frame=CGRectMake(0, -height, [[UIScreenmainScreen]bounds].size.width, [[UIScreenmainScreen]bounds].size.height);

}

}

//当键退出时调用

- (void)keyboardWillHide:(NSNotification*)aNotification

{

self.ps.frame=CGRectMake(0,0, [[UIScreenmainScreen]bounds].size.width, [[UIScreenmainScreen]bounds].size.height);

}

你可能感兴趣的:(键盘监听事件)