views:

358

answers:

1

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!

A: 

Check out the answer to this question...

http://stackoverflow.com/questions/1126726/how-to-make-a-uitextfield-move-up-when-keyboard-is-present

Staros
Hi Staros, thanks for answering! I already took that approach, but I think that in that example what they resize is the view, not the scroll view (and I still want to use a scroll view when the keyboard is shown). Should I resize a view that has a scroll view in it, instead of the scroll view itself, and then scroll to specific text fields? I haven't tried it, is that what you're suggesting? I'll see what I can do when I get home. Thanks again!
Manu
The last of the answers, the one written by "Shiun" did the trick. Thanks!
Manu