Scrolling screen upward to expose TextView above keyboard
- by Matt Winters
I think I'm missing something obvious and would appreciate an answer.
I have a view with a 2-section grouped tableView, each section having one row and a textView, the heights of the rows 335 and 140. This allows for a box with nicely rounded corners to type text into when the keyboard appears (140 height section) and when the keyboard is dismissed, a nice box to read more text (notes); most of the time, use is without the keyboard.
I also added a toolbar at the bottom of the screen to scroll up above the keyboard. A button on the toolbar dismisses the keyboard. This last part works fine with the keyboard going up and down using a notification and the following code in a keyboardWillShow method:
[UIView beginAnimations:@"showKeyboardAnimation" context:nil];
[UIView setAnimationDuration:0.50];
self.view.frame = CGRectMake(self.view.frame.origin.x,
self.view.frame.origin.y,
self.view.frame.size.width,
self.view.frame.size.height - 216);
[UIView commitAnimations];
But with the above code, the 2 sections of the tableView remain unscrolled, only the toolbar and the keyboard move. With the following code (found both in previous posts), both the toolbar and the tableView sections move.
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.50];
CGRect rect = self.view.frame;
rect.origin.y -= 216;
self.view.frame = rect;
[UIView commitAnimations];
Now I know that I have to tweak the numbers to get the everything as I want it but my first question is what is substantively different between the 2 sets of code that the sections move in the 2nd but not in the 1st? The toolbar also moves with the 2nd code.
The second question is, am I going to be able to scroll the smaller height section from off the screen to above the keyboard while at the same time moving the toolbar up just 216?
Thanks