This is working for me:
- (void)keyboardWillShow:(id)keyboardDidShow
{
[UIView beginAnimations:nil context:NULL];
NSDictionary *userInfo = [keyboardDidShow userInfo];
[UIView setAnimationDuration:[userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue]];
[UIView setAnimationCurve:[userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue]];
[self.view layoutIfNeeded];
[UIView commitAnimations];
}
- (void)keyboardWillHide:(id)keyboardDidHide
{
[UIView beginAnimations:nil context:NULL];
NSDictionary *userInfo = [keyboardDidHide userInfo];
[UIView setAnimationDuration:[userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue]];
[UIView setAnimationCurve:[userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue]];
[self.view layoutIfNeeded];
[UIView commitAnimations];
}
UPDATE:
Or you can do the same with blocks:
- (void)keyboardWillShow:(id)keyboardDidShow
{
NSDictionary *userInfo = [keyboardDidShow userInfo];
[UIView animateWithDuration:[userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue]
delay:0.f
options:[[keyboardDidShow userInfo][UIKeyboardAnimationCurveUserInfoKey] intValue] << 16
animations:^{
...
} completion:^(BOOL finished) {
...
}];
}
- (void)keyboardWillHide:(id)keyboardDidHide
{
NSDictionary *userInfo = [keyboardDidHide userInfo];
[UIView animateWithDuration:[userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue]
delay:0.f
options:[[keyboardDidHide userInfo][UIKeyboardAnimationCurveUserInfoKey] intValue] << 16
animations:^{
...
} completion:^(BOOL finished) {
...
}];
}