How to make keyboard with textfield on the top of

2019-08-21 17:01发布

问题:

I need to have textfield (maybe with button) fixed at the bottom of screen, and when start editing, I want it (and probably the whole view) to move with keyboard up - just like in the native Messages application (or Whatsapp, etc...). Any suggestions ?

回答1:

The easiest way is to put everything in a UIScrollView, which you resize when the keyboard is shown using the UIKeyboardDidShowNotification. Then you scroll to ensure that your views are visible.

Check out the Apple documentation under "Moving Content That Is Located Under the Keyboard"