简体   繁体   English

如何摆脱UITextField和Keyboard之间的空间

[英]How to get rid of space between UITextField and Keyboard

I was wondering if anyone has seen a similar problem to this where you have a random blank space between the keyboard and a UITextField? 我想知道是否有人看到过类似的问题,您在键盘和UITextField之间有一个随机的空格? For some reason I can't find anything about this and the end of the screen is the bottom of the UITextField. 由于某种原因,我对此一无所获,屏幕的结尾是UITextField的底部。 Any help would be greatly appreciated. 任何帮助将不胜感激。

Example Screenshot showing space between keyboard and UITextField 屏幕截图示例显示了键盘和UITextField之间的空间

  1. Start by putting the text field in a UIScrollView . 首先将文本字段放入UIScrollView
  2. Register your view controller to respond to the notification UIKeyboardDidShowNotification . 注册您的视图控制器以响应通知UIKeyboardDidShowNotification This notification will give you a dictionary that has the size of the keyboard. 此通知将为您提供具有键盘大小的字典。
  3. Once you have the size value, you will have to do some math to figure out what you want the scroll view's contentInset to be such that the text field is just above it. 获得大小值后,您将必须做一些数学运算才能弄清楚滚动视图的contentInset要的contentInset ,以使文本字段位于其上方。

Here's an example for getting the size of the keyboard: How to get UIKeyboard size with Apple iPhone SDK 这是获取键盘大小的示例: 如何使用Apple iPhone SDK获取UIKeyboard大小

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM