2

I have had a simple UIView block animation that handles animating a group of text fields into view when the keyboard will show (and animate them back when the keyboard hides). This has worked fine in iOS 6 & 7, but now I'm getting incorrect behavior, and it all points to some change in UIKeyboardWillShowNotification.

I set up an isolated project to test this further on a single text field, with two buttons that call exactly the same methods that are fired for the keyboard's WillShow and WillHide notifications. See the results in this video:

Video example

This seems like a bug to me, or it might be a change to the behavior of this notification. Does anyone know if this is intended and/or what can be done about it?

Here is the relevant code:

- (void)viewWillAppear:(BOOL)animated
{
     [super viewWillAppear:animated];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}

- (void)viewWillDisappear:(BOOL)animated
{
     [super viewWillDisappear:animated];
     [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
     [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}

- (void)keyboardWillShow:(NSNotification *)notification
{
     [UIView animateWithDuration:0.3 animations:^{
          self.textField.frame = CGRectOffset(self.textField.frame, 0.f, _destY - _origY);
     }];
}

- (void)keyboardWillHide:(NSNotification *)notification
{
     [UIView animateWithDuration:0.3 animations:^{
          self.textField.frame = CGRectOffset(self.textField.frame, 0.f, _origY - _destY);
     }];
}
Chris
  • 556
  • 1
  • 4
  • 18
  • I am seeing the notification for UIKeyboardWillShowNotification called (even if the keyboard is already showing) when switching between text fields on iOS8. In iOS7 it is only called if the keyboard is not already showing. – Brett Nov 12 '14 at 03:59
  • I get notifications for `UIKeyboardWillHide` and `UIKeyboardWillShow`, successively, when the interface rotates and the keyboard is already up – shoe Feb 18 '17 at 20:34

0 Answers0