iosuiscrollviewuitextfieldiphone-softkeyboard

TextField is not pushed up smoothly by keyboard, like in Whatsapp and Hangouts


I'm trying to mimic the UITextField-keyboard relation in Whatsapp app. As most of you know, there is a fixed UITextField at the bottom of the screen and keyboard comes up as you tap the UITextField. While keyboard is coming up, UITextField stick to the keyboard and they slide together very smoothly.

Read Apple's documentation pages which is about moving views under the keyboard several times.

What I have tried so far:

At last, I thought Whatsapp might not be using system keyboard but a custom one. But if this is the case, it is a very very bad choice of design so that option is eliminated.

Anyone has an idea of how Whatsapp (or Hangouts) implemented that?


Solution

  • The most straightforward way of doing that turned out to be the correct way.

    I should have listened to keyboardWillShow/keyboardWillHide notifications and animateWithDuration: as they are triggered. The point I missed was casting UIViewAnimationCurve into UIViewAnimationOptionCurve by shifting (<<16).

    NSDictionary *notification = [aNotification userInfo];
    UIViewAnimationOptions curveValue = [[info objectForKey:UIKeyboardAnimationCurveUserInfoKey] unsignedIntegerValue] << 16;
    ...
    [UIView animateWithDuration:{animation duration}
                          delay:0
                        options:curveValue
                     animations:^{
                         //animation code
                     }
                     completion:nil];