开发者

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

This question already has answers here: Closed 10 years ago.

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜