Update, fixed in 7.1. No longer necessary.
For whatever reason, the animation curve reported on keyboard dismissal is incorrect. It seems to actually be 6 << 16 instead of 7 << 17.
Here's what I do with UIKeyboardWillChangeFrameNotification
to determine which animation curve to use.
NSDictionary *keyboardAnimationDetail = [notification userInfo];
CGRect keyboardEndFrameWindow = [keyboardAnimationDetail[UIKeyboardFrameEndUserInfoKey] CGRectValue];
double keyboardTransitionDuration = [keyboardAnimationDetail[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
// gives incorrect value of 7 on dismissal
// UIViewAnimationCurve keyboardTransitionAnimationCurve = [keyboardAnimationDetail[UIKeyboardAnimationCurveUserInfoKey] integerValue];
CGRect keyboardEndFrameView = [self.view convertRect:keyboardEndFrameWindow fromView:nil];
CGFloat newConstant = (self.view.frame.size.height - keyboardEndFrameView.origin.y);
[UIView animateWithDuration:keyboardTransitionDuration
delay:0.0f
options:newConstant == 0 ? (6 << 16) : (7 << 16)
animations:^{
self.tableView.contentInset = UIEdgeInsetsMake(self.tableView.contentInset.top, 0, self.view.frame.size.height - keyboardEndFrameView.origin.y + self.commentToolbar.frame.size.height, 0);
self.tableView.scrollIndicatorInsets = UIEdgeInsetsMake(self.tableView.scrollIndicatorInsets.top, 0, self.view.frame.size.height - keyboardEndFrameView.origin.y + self.commentToolbar.frame.size.height, 0);
self.commentViewToSuperviewBottomConstraint.constant = (self.view.frame.size.height - keyboardEndFrameView.origin.y);
[self.view layoutIfNeeded];
}
completion:^(__unused BOOL finished){
}];
Basically I determine if the keyboard frame is hiding by seeing if the new y origin will be just outside our view's frame (newConstant
). Then based on that I use either 6 or 7:
newConstant == 0 ? (6 << 16) : (7 << 16)
The rest is just adjusting my tableView
contentInset
and scrollIndicatorInsets
, as well as changing the constant on the toolbar that is moving with the keyboard.