Get the size of the iPad screen keyboard after rotation

For the app I’m designing for the iPad, I have a scroll view that contains some text fields/text views. To keep everything visible, I adjust the contentSize property of the scroll view, in Add a buffer at the bottom that corresponds to the degree to which the keyboard overlaps the scroll view. Here is the code (here are some application-specific things, but hopefully not so much, you can’t understand it):

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];

NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[nc addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}


- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];

NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc removeObserver:self name:nil object:nil];
}

- (void)keyboardWillShow :(NSNotification *)aNotification
{
NSValue *animationCurve = [[aNotification userInfo] valueForK ey:UIKeyboardAnimationCurveUserInfoKey];
UIViewAnimationCurve curve;
[animationCurve getValue:&curve];

NSValue *animationDuration = [[aNotification userInfo] valueForKey:UIKeyboardAnimationDurationUserInfoKey];
NSTime duration;
[animationDuration getValue:&duration];

NSValue *endingFrame = [[aNotification userInfo] valueForKey:UIKeyboardFrameEndUserInfoKey];
CGRect frame;
[endingFrame getValue: &frame];

[UIView beginAnimations:@"keyboardWillShow" context:bodyView];
[UIView setAnimationCurve:curve];
[UIView setAnimationDuration:duration];

// Re-draw code here.

[UIView commitAnimations];
}

- (void)keyboardWillHide:(NSNotification *)aNotification< br />{

NSValue *animationCurve = [[aNotification userInfo] valueForKey:UIKeyboardAnimationCurveUserInfoKey];
UIViewAnimationCurve curve;
[animat ionCurve getValue:&curve];

NSValue *animationDuration = [[aNotification userInfo] valueForKey:UIKeyboardAnimationDurationUserInfoKey];
NSTimeInterval duration;
[animationDuration getValue:&duration];

[UIView beginAnimations:@"keyboardWillHide" context:bodyView];
[UIView setAnimationCurve:curve];
[UIView setAnimationDuration:duration];

// Re -draw code here

[UIView commitAnimations];
}

My question is: How do I handle the keyboard size during rotation? When rotating the iPad, I did not receive any keyboard notifications, but the size of the keyboard has changed significantly. Ideally, I only need to adjust the amount of overlap of the keyboard in landscape mode to the height of the contentSize property, but if it is not two Hard-coding the height of the keyboard in the direction, I can’t see a good way to do this. I don’t want to do it.

I stumbled upon this debugging answer. It turns out that when the iPad is rotated from portrait to landscape, the portrait keyboard will hide (and send its notification) (and send its notification) before the landscape keyboard appears. So, just You state this and you are fine.

For the app I am designing for the iPad, I have a scroll view with some text fields/text views. To keep everything visible , I adjusted the contentSize property of the scroll view and added a buffer at the bottom that corresponds to the degree to which the keyboard overlaps the scroll view. This is the code (here are some application-specific things, but hopefully not so much, you Can’t understand it):

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];

NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[nc addObserver:self selector :@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}


- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];

NSNotificationCent er *nc = [NSNotificationCenter defaultCenter];
[nc removeObserver:self name:nil object:nil];
}

- (void)keyboardWillShow:(NSNotification *)aNotification
{
NSValue *animationCurve = [[aNotification userInfo] valueForKey:UIKeyboardAnimationCurveUserInfoKey];
UIViewAnimationCurve curve;
[animationCurve getValue:&curve];

NSValue *animationDuration = [[aNotification userInfo] valueForKey:UIKeyboardAnimationDurationUserInfoKey];
NSTimeInterval duration;
[animationDuration getValue:&duration];

NSValue *endingFrame = [[aNotification userInfo] valueForKey: UIKeyboardFrameEndUserInfoKey];
CGRect frame;
[endingFrame getValue:&frame];

[UIView beginAnimations:@"keyboardWillShow" context:bodyView];
[UIView setAnimationCurve: curve];
[UIView setAnimationDuration:duration];

// Re-draw code here.

[UIView commitAnimations] ;
}

- (void)keyboardWillHide:(NSNotification *)aNotification
{

NSValue *animationCurve = [[aNotification userInfo] valueForKey:UIKeyboardAnimationCurveUserInfoKey ];
UIViewAnimationCurve curve;
[animationCurve getValue:&curve];

NSValue *animationDuration = [[aNotification userInfo] valueForKey:UIKeyboardAnimationDurationUserInfoKey];
NSTimeInterval duration;< br /> [animationDuration getValue:&duration];

[UIView beginAnimations:@"keyboardWillHide" context:bodyView];
[UIView setAnimationCurve:curve];
[UIView setAnimationDuration: duration];

// Re-draw code here

[UIView commitAnimations];
}

My problem is: rotating How do I deal with the keyboard size during the process? When rotating the iPad, I did not receive any keyboard notifications, but the size of the keyboard has changed significantly. Ideally, I only need to adjust the amount of overlap of the keyboard in landscape mode to the height of the contentSize property, but if it is not two Hard-coding the height of the keyboard in the direction, I can’t see a good way to do this. I don’t want to do it.

I stumbled upon this debugging answer It turns out that when the iPad is rotated from portrait to landscape, the portrait keyboard will hide (and send its notification) (and send its notification) before the landscape keyboard appears. So, as long as you state this, you are fine.

Leave a Comment

Your email address will not be published.