问题描述
当我的UITextField成为第一响应者(编辑时)时,文本会略微向下移动,并且字符之间的间距会略微增加。在辞职第一响应者(键盘消失)后,角色移回原始位置。起初我认为这是一个字体问题,因为我使用的是自定义字体,但是当我使用系统字体或其他自定义字体时会发生同样的事情。
When my UITextField becomes first responder(on edit) the text is moving down very slightly and the spacing between the characters is increased very slightly. Upon resign first responder(keyboard goes away), the characters move back to the original positioning. At first I thought this was a font issue, as I am using a custom font, but the same thing happens when I use the system font or other custom fonts.
请检查下面的图像。第一个是键盘向下,第二个是键盘向上。可能很难看到,因为方差很小,但键盘向上状态显示字符向下移动并稍微分开。
Please check the images below. The first one is with the keyboard down and the second is with the keyboard up. It may be difficult to see, as the variance is small, but the keyboard up state shows the characters moved down and apart slightly.
推荐答案
在xib中,将textfield的borderStyle设置为any值比TextBorderStyleNone。在代码中,将textfield的borderStyle显式设置为TextBorderStyleNone。
In xib, set textfield's borderStyle to any value than TextBorderStyleNone . And in code, set textfield's borderStyle as TextBorderStyleNone explicitly.
我无法找出原因,但它似乎是初始化程序错误。它在其他代码中工作正常,它不会通过xib的outlet初始化UITextField。
I could'n figure out why but it seems like initializer bug. It works fine in other code which doesn't initialize UITextField by outlet from xib.
当在xib中将textfield的borderStyle设置为TextBorderStyleNone时,即使将borderStyle设置为as,问题仍然存在代码中的TextBorderStyleNone。可能会出现某种'layoutIfNeeded'的东西,这是由价值变化引发的。
When set textfield's borderStyle as TextBorderStyleNone at xib, the problem still remains even if set borderStyle as TextBorderStyleNone in code. It may be followed by some kind of 'layoutIfNeeded' stuff, which triggered by value change.
这篇关于UITextfield文本正在进行编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!