1.系统的通知,无论什么键盘弹出的时候都会post这个事件
[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(KeyboardWillShow:)name:UIKeyboardWillShowNotificationobject:nil];
2.name。// 很容易看懂
UIKIT_EXTERN NSNotificationNameconst UIKeyboardWillShowNotification__TVOS_PROHIBITED;
UIKIT_EXTERN NSNotificationNameconst UIKeyboardDidShowNotification__TVOS_PROHIBITED;
UIKIT_EXTERN NSNotificationNameconst UIKeyboardWillHideNotification__TVOS_PROHIBITED;
UIKIT_EXTERN NSNotificationNameconst UIKeyboardDidHideNotification__TVOS_PROHIBITED;
3.键盘出现时,点击view可收回,(实现在 带手势的view上添加了tableview 而tableview 会响应view的UITapGestureRecognizer手势,而无法点击, 所以在键盘收起时,移除手势UITapGestureRecognizer)
-(void)KeyboardWillShow:(NSNotification *)notification
{
// NSLog(@"键盘出现");
UITapGestureRecognizer *tap = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(reKeyBoard)];
[self.viewaddGestureRecognizer:tap];
// [self.view endEditing:YES];
}
-(void)KeyboardWillHide:(NSNotification *)notification
{
for (UIGestureRecognizer *gestin self.view.gestureRecognizers) {
[self.viewremoveGestureRecognizer:gest];
}
// NSLog(@"键盘收起,%@",self.view.gestureRecognizers);
}