Вы можете попробовать этот код:
- (BOOL) findKeyboard:(UIView *) superView;
{
UIView *currentView;
if ([superView.subviews count] > 0) {
for(int i = 0; i < [superView.subviews count]; i++)
{
currentView = [superView.subviews objectAtIndex:i];
NSLog(@"%@",[currentView description]);
if([[currentView description] hasPrefix:@"<UIKeyboard"] == YES)
{
NSLog(@"Find it");
return YES;
}
if ([self findKeyboard:currentView]) return YES;
}
}
return NO;
}
-(void) checkKeyBoard {
UIWindow* tempWindow;
for(int c = 0; c < [[[UIApplication sharedApplication] windows] count]; c ++)
{
tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:c];
if ([self findKeyboard:tempWindow])
NSLog(@"Finally, I found it");
}
}
- (void)keyboardWillShow:(NSNotification *)note {
[self performSelector:(@selector(checkKeyBoard)) withObject:nil afterDelay:0];
}
И вам также нужно добавить этот код в функцию didFinishLaunchingWithOptions в AppDelegate:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];