adding a textbox and a button at the top of the keyboard on iphone

夙愿已清 提交于 2019-12-10 11:14:28

问题


I want to add a text box and a button beside it. They will be at the bottom of the window. Then, when I touch the textbox (to type something), keyboard will appear and the whole row (with textbox and button) scrolls up and the keyboard will be right below them. Could you please let me know how can I do that?

Is there any sample program?

Thanks.


回答1:


Matt Gallagher posted this on his blog:

Sliding UITextFields around to avoid the keyboard

It is a step by step example of exactly what you want.




回答2:


In the XCode documentation iPhone Application Programming Guide there is a section on "Moving Content That Is Located Under the Keyboard" that talks about receiving keyboard notifications when a keyboard is about to show. There's code there to show you how to get the keyboard size (which varies depending on the orientation). I won't repeat it here.

You can use the same technique to get the UIKeyboardWillShowNotification notification and get the height of where the keyboard will end up. That gives you the bottom edge of where your view needs to go, effectively putting it above the keyboard. So just put your textbox and button inside a view. When you get the notification tell your view where it needs to go (keyboard height + height of the container view) and you're done. You'll also want to catch UIKeyboardWillHideNotification to move the view back to where it was, so keep track of the original container view position.

It's pretty straightforward and it'll look nice, especially if you use a nice UIView animation effect and set the timing just right.



来源:https://stackoverflow.com/questions/866532/adding-a-textbox-and-a-button-at-the-top-of-the-keyboard-on-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!