Scroll view to bottom while keyboard is hiding
- by Manu
Hi!
I'm using a scroll view to move my view and show certain text fields (that otherwise would be hidden) when the keyboard shows. I basically resize the scroll view to make room for the keyboard, and then scroll up the view smoothly with "scrollRectToVisible", which works perfectly. After that, I can scroll and edit the rest of the text fields without lowering the keyboard, which is what I intend.
The problem comes when I want to hide the keyboard again. I have been able to lower the keyboard and scroll down the view to its original position without a problem, but I have been unable to make that transition smooth.
At the moment I use the following:
- (void)keyboardWillHide: (NSNotification *)notif {
CGRect topRect = CGRectMake(0, 0, 1, 1);
[scrollview scrollRectToVisible:topRect animated:YES];
scrollview.frame = CGRectMake(0, 0, scrollviewWidth, scrollviewHeight);
}
I create a CGRect at the top, which I then move into view with "scrollRectToVisible". That works fine and commences the scrolling right when the keyboard is hiding (I use "keyboardWillHide" and not "keyboardDidHide" because the scroll view frame is still missing its lower part).
The problem comes when I resize the scroll view frame back to its original dimensions (which I need to do), because then the scrolling is interrupted and the view drops to the bottom suddenly (as there is nothing else to scroll). This causes a glitch, which is why I cannot complete the transition smoothly.
Any ideas on how could I lower the keyboard while scrolling the view down smoothly?
Should I be scrolling up a bigger view, instead of resizing it? That way I would not have to restore the scroll view frame dimensions when lowering the keyboard, or would I?
Thanks very much in advance!