6

Possible Duplicate:
UITableView and keyboard scrolling issue

I've got a screen which has several text fields (UITextField) for gathering information from the user which ends up taking up most of the screen. when the user selects a field the soft keyboard appears (as expected) but it covers up the fields that appear further down on the screen. In order to get to those fields the user has to close the keyboard and select them, and upon doing so, the field is covered up again and the user can't see what they're typing.

I tried wrapping the text fields in a UIScrollView, hoping that when the keyboard took up space on the screen i would be able to scroll the uppper portion of the screen down to the other text fields, but this did not work.

I'm hoping to get this scrolling behavior. Does anyone know how to do it?

-TIA

Community
  • 1
  • 1
mtmurdock
  • 12,756
  • 21
  • 65
  • 108

3 Answers3

9

You need to adjust the height of your scroll view when the keyboard appears so that it doesn't overlap. See Managing the Keyboard in the programming guide.

Brian
  • 15,599
  • 4
  • 46
  • 63
  • See section "Moving Content That Is Located Under the Keyboard". It has source code with it as well – bryanmac Jun 27 '12 at 02:21
4

There's a good answer to a similar question and some sample code here.

Basically, you register to receive the UIKeyboardWillShowNotification and the UIKeyboardWillHideNotification, then you manually scroll the view to compensate.

Community
  • 1
  • 1
djeckhart
  • 89
  • 2
  • That is a great article, but unfortunately it focuses on UITableView and thats not what I'm using here. I'm not sure how i would adapt that to a normal view. – mtmurdock Jan 21 '11 at 17:57
  • I have accepted this answer because it was the most detailed, but it was really this one and the answer from Brian that helped me figure out what to do. – mtmurdock Jan 21 '11 at 18:12
2

This is a drag and drop framework that I use in my projects as I have come across this problem a lot. It's a UIScrollView subclass and supports different auto-focus modes and a variety of other bits and bobs.

https://github.com/mackross/GTKeyboardHelper

mackross
  • 2,234
  • 17
  • 19