13

Possible Duplicate:
How to make a UITextField move up when keyboard is present

I'm trying to implement something very similar to the "chat like" screen of the iPhone sms app. Basically, it has a ScrollView with all the message bubbles, and a TextField at the bottom, for writing a new message.

When the TextField is clicked, the keyboard appears and everything seems to scroll upwards so that the TextField is over the keyboard and not hidden by it.

Apple's docs suggest implementing a screen that should support the appearance of a keyboard, using a ScrollView that resizes when the keyboard appears (while maintaining the same contentsize). In my case, that would mean I need a ScrollView to contain the whole chat screen (messages and TextField), so everything would resize neatly on keyboard appearance. However, the messages are already inside a ScrollView, and this behavior is not supported.

The only choice I can see, is somehow implementing the refitting behavior on my own, without using the external ScrollView. But that would seem like a lot of delicate coding for the scrolling and resizing animations of both the message bubbles and the TextField to work perfectly.

What should I do?

Community
  • 1
  • 1
DannyA
  • 1,571
  • 2
  • 17
  • 28
  • You might want to check the answer here: http://stackoverflow.com/questions/1126726/how-to-make-a-uitextfield-move-up-when-keyboard-is-present – joshpaul Dec 25 '10 at 22:29
  • This is a different situation than that answer. In that case the question was about ensuring that when the scrollview was resized, a specific text field inside the scrollview stayed visible. In this case, as in the native SMS app, the textfield should *not* scroll, but instead stay still below the scrolling area. Two completely different problems that sound similar due to the use of a scrollview and a textfield and resizing due to keyboard appearance. – Matthew Frederick Dec 26 '10 at 06:21
  • So you're looking to resize the text fields (aka bubble chats) as well? Kind of "shrinking" the entire view to fit on screen? – joshpaul Dec 26 '10 at 18:10

1 Answers1

2

The scrollview resizing is effectively done manually, checking the height of the keyboard and shortening the scrollview by its height.

In the case of he SMS screen, the text field isn't in the scrollview, so you simply have a scrollview sitting above a uiview that contains the posting bits. When the keyboard appears you shrink the scrollview as normal and slide the uiview up by that same keyboard-height amount.

There's nothing magical about shrinking the scrollview as Apple suggests: moving views is just as easy and sensible.

Matthew Frederick
  • 22,245
  • 10
  • 71
  • 97
  • I guess you're right. I hoped the scrolling technique apple suggested would be applicable here (and in similar places), so that I could implement some kind of "generalized" behavior, for all ViewControllers that need to respond to keyboard input in my app. It seems that there is no choice but move the view myself, like you've suggested. Thanks! – DannyA Dec 26 '10 at 21:52