UITextField UIKeyboardWillShowNotification sent for every UITextField on a screen in iOS9 even while keyboard is visible

Using iOS9 GM, I have a screen with two UITextFields. When I tap in the first field a UIKeyboardWillShowNotification is received. With the keyboard still up, when I tap in the second field the app receives another UIKeyboardWillShowNotification. If I tap in the first field the app receives yet another UIKeyboardWillShowNotification. At no stage has the keyboard been dismissed.


This happens in both the simulator (XCode 7.0 GM) and an iPad mini 2 running iOS9 GM.


In iOS8.4 the above does not occur. There is only one UIKeyboardWillShowNotification.


In addition, I am being advised of different behaviour with an iPad Air with iOS9 GM: it appears that it may not be receiving the UIKeyboardWillHideNotification.


Has anyone experienced these two behaviours, or can explain why an Air would be different to an iPad mini 2?


Thank you.

Have the same issue on iOS 9, so add some check if keyboard already shown, would not process "UIKeyboardWillShowNotification". Same check for "UIKeyboardWillHideNotification"

I found that UIKeyboardWillHideNotification is not called if the keyboard is not hidden completely on iPad Air 2 (iOS 9, simulator). See the image Xp91Q30.png

In this position you won't receive UIKeyboardWillHideNotification.


Try using UIKeyboardWillChangeFrameNotification instead of separate Show/Hide notifications. The keyboard's frame can change size without fully disappearing in some situations. For example, switching to an external keyboard will hide most of the keyboard but keep the quick bar on screen as in Vitaly's screenshot. The user can choose to show/collapse the quick bar and I think it's even possible to change size slighly when switching between certain keyboard languages.


Here's some code I have in one of my apps that changes the size of a vertical height constraint at the bottom of my main view to the bottom of its superview to make my whole UI "compress" in height when the keyboard is visible. It's based on an answer on Stack Overflow http://stackoverflow.com/a/27665207/870671


The animationCurve << 16 is used to convert a UIViewAnimationCurve value to a UIViewAnimationOptions value. They keyboard uses a non-documented animation curve value. I can't remember where I found this trick.



- (void)keyboardWillChangeFrameNotification:(NSNotification *)notification
{
    NSDictionary *userInfo = notification.userInfo;
    CGRect keyboardFrameEnd = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    UIViewAnimationCurve animationCurve = [userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue];
    double animationDuration = [userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    CGRect convertedKeyboardFrameEnd = [self.view convertRect:keyboardFrameEnd fromView:nil];

    // Adjust the vertical space beneath our content to leave room for the keyboard (if any)
    self.contentContainerViewBottomSpaceConstraint.constant = self.view.bounds.size.height - convertedKeyboardFrameEnd.origin.y;;
    [UIView animateWithDuration:animationDuration
                          delay:0.0
                        options:animationCurve << 16
                     animations:^{
                         [self.view layoutIfNeeded];
                     } completion:nil];
}
UITextField UIKeyboardWillShowNotification sent for every UITextField on a screen in iOS9 even while keyboard is visible
 
 
Q