有时我们需要判断键盘的显示状态,以便做后续的处理,下面的代码是写了一个单例进行判断
-(id)init{
self = [super init];
if (self)
{
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(keyboardDidShow) name:UIKeyboardDidShowNotification object:nil];
[center addObserver:self selector:@selector(keyboardDidHide) name:UIKeyboardWillHideNotification object:nil];
_keyboardIsShow = NO;
}
return self;
}
- (void)keyboardDidShow
{
_keyboardIsShow = YES;
}
- (void)keyboardDidHide
{
_keyboardIsShow = NO;
}
- (BOOL)keyboardIsVisible
{
return _keyboardIsShow;
}