3

I have the following observer in my ViewController.

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];

This view controller also conforms to the UITextFieldDelegate and UITextViewDelegate and implements textFieldDidBeginEditing and textViewDidBeginEditing.

Now, here's the weird part.

If you tap on the UITextField, the order of calls is textFieldDidBeginEditing AND THEN keyboardWillChangeFrame:.

If you tap on the UITextView, the order of calls is keyboardWillChangeFrame AND THEN 'textViewDidBeginEditing'.

Anyone not see a problem with this? Shouldn't text_____DidBeginEditing be called first no matter whether it's a Field or View. Why is this?

It's leading to weird animation issues. I need it to be consistent one way or the other.

chris P
  • 6,359
  • 11
  • 40
  • 84
  • Can I ask you why are you using UIKeyboardWillChangeFrameNotification? I just did. – Everton Cunha May 19 '15 at 19:36
  • @Everton To animate up view to accommodate for the growing the keyboard. My UITextView more or less takes up 90% of the view. When the keyboard comes on screen, I animate up the height of the UITextView to be above the Keyboard. When the keyboard disappears, I animate it back it down. – chris P May 19 '15 at 19:41

2 Answers2

0

I believe you can use the UIKeyboardWillShowNotification, and something like the above code for what you are trying to do:

- (void)keyboardWillShowNotification:(NSNotification*)notification {
    NSDictionary *info = notification.userInfo;

    CGRect r = [info[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    r = [self.view convertRect:r fromView:nil];

    UIViewAnimationCurve curve = [info[UIKeyboardAnimationCurveUserInfoKey] integerValue];
    double duration = [info[UIKeyboardAnimationDurationUserInfoKey] doubleValue];

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:curve];
    [UIView setAnimationDuration:duration];

    /* view changes */

    [UIView commitAnimations];
}
Everton Cunha
  • 1,017
  • 8
  • 10
0

Use UIKeyboardDidChangeFrameNotification instead of UIKeyboardWillChangeFrameNotification.

AndyW
  • 985
  • 3
  • 10
  • 21