Post not yet marked as solved
Post marked as unsolved with 0 replies, 921 views
Hi,
I have a view with a texfield and when the keyboard appears sometimes I get the wrong height. I get the wrong value when I made a long tap in the textfield. With the normal tap I get the correct value. I get the wrong value only on iOS 14 and iOS 15 devices.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
-(void)keyboardWillShow:(NSNotification *)notification
{
if(self.keyboardIsShown) {
return;
}
if (keyboardHeight == 0) {
// grab keyboard size
NSDictionary *userInfo = notification.userInfo;
NSValue *keyFrame = [userInfo valueForKey:UIKeyboardFrameBeginUserInfoKey];
CGRect keyboardFrame = keyFrame.CGRectValue;
keyboardHeight = keyboardFrame.size.height;
}
// move the root view up by the distance of keyboard height
self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y - keyboardHeight, self.view.frame.size.width, self.view.frame.size.height);
self.keyboardIsShown = YES;
}