For the Im app designed for iPad, I have a scroll view with some text fields / text views in it. To make everything visible, I adjust the scroll contentSize property to add a buffer at the bottom that matches how much the keyboard overlaps the scroll view. Here is the code (there are some applications for a specific application here, but hopefully not so much that you cannot understand this):
- (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] 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];
My question is: what should I do with the keyboard size during rotation? I do not receive any keyboard notifications when the iPad rotates, but the size of the keyboard changes significantly. Ideally, Id just adjusts the height of the contentSize property to the amount of keyboard overlap in landscape mode, but I donβt see a good way to do this without hard-coding the keyboard height in both orientations, which I donβt know how to do.
ios uikeyboard ipad
Jeff kelley
source share