1.注册键盘通知
//注册键盘出现通知;
[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(keyboardDidShow:)name:UIKeyboardDidShowNotificationobject:nil];
//注册键盘消失通知;
[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(keyboardDidHide:)name:UIKeyboardDidHideNotificationobject:nil];
-(void)keyboardDidShow:(NSNotification *)notification
{
//键盘打开;
}
-(void)keyboardDidHide:(NSNotification *)notification
{
//键盘关闭
}
3.视图将要消失的时候删除键盘通知;
-(void)viewWillDisappear:(BOOL)animated
{
//解除键出现盘通知;
[[NSNotificationCenterdefaultCenter]removeObserver:selfname:UIKeyboardDidShowNotificationobject:nil];
//解除键盘隐藏通知;
[[NSNotificationCenterdefaultCenter]removeObserver:selfname:UIKeyboardDidHideNotificationobject:nil];
}