0

Previously as noted in a few questions:

How to detect iPad user tap on keyboard hide button?

detect iPad keyboard Hiding button

...the way to detect if the user hit the hide keyboard button on an iPad was to subscribe to the UIKeyboardWillHideNotification notification.

However, apparently from iOS 6 on, this notification has been sent in a number of places not just when the user hits the retract keyboard button. For example, that notification is sent when the iPad rotates even though the keyboard itself does not hide.

I have discovered an inelegant work around, which I will post here in case anyone else is struggling with this problem, but would much appreciate any elegant solutions people have found to this problem.

Community
  • 1
  • 1
aepryus
  • 4,715
  • 5
  • 28
  • 41

1 Answers1

0

The current solution I have come up with for this problem is to note that the only time the keyboard actually retracts during this notification is if the user actually hits the retract button. In other cases there is nearly 0 delay between the UIKeyboardWillHideNotification and the UIKeyboardDidHideNotification.

static BOOL immediate;

- (void) checkImmediate {
    if (immediate) return;
    /* Do Stuff */
}
- (void) keyboardWillHide:(NSNotification*)note {
    immediate = NO;
    [self performSelector:@selector(checkImmediate) withObject:self afterDelay:.01 inModes:@[NSRunLoopCommonModes]];
}
- (void) keyboardDidHide:(NSNotification*)note {
    immediate = YES;
}
aepryus
  • 4,715
  • 5
  • 28
  • 41
  • What about observing `window.firstResponder`? I think it will change when the keyboard is dismissed? – nielsbot Dec 05 '13 at 20:19