I use below code to get keyboard height. Then use this height to calculate the frame of an UIView
to make sure this UIView
just on the top of the k
This works for every device and iOS version so far
- (void)keyboardWillShown:(NSNotification*)aNotification
{
NSDictionary* info = [aNotification userInfo];
CGFloat kbHeight = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height;
CGFloat safeAreaBottomInset = 0;
if (@available(iOS 11.0, *)) {
safeAreaBottomInset = self.view.safeAreaInsets.bottom;
}
self.containerViewBottomConstraint.constant += (kbHeight - safeAreaBottomInset); //In my case I use a constraint to adapt the UI when the keyboard is presented
[self.view layoutIfNeeded];
}