16

UITextField がファーストレスポンダー (編集時) になると、テキストがわずかに下に移動し、文字間の間隔がわずかに広がります。ファーストレスポンダーを辞任すると(キーボードが消える)、キャラクターは元の位置に戻ります。カスタムフォントを使用しているため、最初はフォントの問題だと思いましたが、システムフォントや他のカスタムフォントを使用しても同じことが起こります。

以下の画像をご確認ください。1 枚目はキーボードを下げた状態、2 枚目はキーボードを上げた状態です。分散が小さいので見にくいかもしれませんが、キーボードを上げた状態では、文字が下に移動してわずかに離れていることがわかります。

ここに画像の説明を入力

ここに画像の説明を入力

4

9 に答える 9

4

xib で、textfield の borderStyle を TextBorderStyleNone 以外の任意の値に設定します。コードでは、textfield の borderStyle を TextBorderStyleNone として明示的に設定します。

理由はわかりませんでしたが、イニシャライザのバグのようです。xib からのアウトレットで UITextField を初期化しない他のコードでは問題なく動作します。

xib で textfield の borderStyle を TextBorderStyleNone に設定すると、コードで borderStyle を TextBorderStyleNone に設定しても問題が残ります。その後に、値の変更によってトリガーされる、ある種の「layoutIfNeeded」が続く場合があります。

于 2016-12-09T06:56:47.043 に答える
3

Selecting the "adjust to fit" property sets the property adjustsFontSizeToWidth in UITextField.

That has this property (UITextField Apple Documentation):

Normally, the text field’s content is drawn with the font you specify in the font property. If this property is set to YES, however, and the contents in the text property exceed the text field’s bounding rectangle, the receiver starts reducing the font size until the string fits or the minimum font size is reached. The text is shrunk along the baseline.

The default value for this property is NO. If you change it to YES, you should also set an appropriate minimum font size by modifying the minimumFontSize property.

I would try first unchecking this and seeing if that would stop it, and then follow the documentation advice and set the minimumFontSize property lower otherwise, which may also be causing the problem.

This issue could possibly be a result of the appearance of the blue "now editing" cursor. The baseline of a text (reference) is the bottom of the text. Your text is shrinking "along the baseline" by pushing down, which leans more strongly in the direction of it being a minimumFontSize/adjustsFontSizeToWidth issue.

于 2013-08-31T01:28:09.090 に答える
1

UITextField のサイズが高さ方向に少し小さすぎる可能性があります。手動でサイズを変更して、1 ピクセルか 2 ピクセル高くしてみてください。または、XIB エディターでそれを選択し、エディター メニューの [コンテンツに合わせてサイズを変更] を使用します。このテキストのシフトが発生しないように、テキスト フィールドを適切なサイズに設定する必要があります。

于 2013-08-31T00:10:42.087 に答える
1

ストーリーボードの制御下で垂直方向の配置を変更すると、うまくいきました。

于 2018-04-23T15:56:24.010 に答える