Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IPhone: How to implement scrolling behavior, similar to iPhone SMS app [duplicate]

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?

like image 208
DannyA Avatar asked Dec 25 '10 14:12

DannyA


1 Answers

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.

like image 159
Matthew Frederick Avatar answered Oct 28 '22 14:10

Matthew Frederick