iPad UITextField - 使用contentVerticalAlignment = UIControlContentVerticalAlignmentCenter调整帧大小时光标不居中 [英] iPad UITextField -- cursor not centering when resizing frame with contentVerticalAlignment = UIControlContentVerticalAlignmentCenter

查看:291
本文介绍了iPad UITextField - 使用contentVerticalAlignment = UIControlContentVerticalAlignmentCenter调整帧大小时光标不居中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一款通用的iPhone / iPad应用程序。我在用户输入时调整了一些UITextField的大小。我还有一些代码来移动UITextFields,以便在调整大小时它们的位置有意义。这段代码不是太短,但基本上它归结为修改UITextFields的帧。

I am working on a universal iPhone/iPad app. I resize some of my UITextFields as the user types. I also have some code to move the UITextFields around so that their locations make sense as they are resized. This code is not too short, but basically it comes down to modifying the frames of the UITextFields.

我的UITextField都通过设置

My UITextFields all have their content vertically centered by setting

textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

文本中心就好了。但是当我在iPad上调整文本字段的大小时,光标有时会出现在框的顶部。用户看起来很奇怪,因为文本位于中心。

The text centers just fine. But when I resize the textfield on the iPad, the cursor sometimes goes to the top of the box. This looks strange to the user as the text is in the center.

这总是发生在iPad上,而不是iPhone上。更糟糕的是,我无法隔离代码的哪个特定部分导致它发生 - 除非我停止调整大小,问题就会消失。

This always happens on the iPad, never on the iPhone. Making matters worse, I can't isolate which particular part of the code causes it to happen -- except that if I stop resizing things, the problem goes away.

已经有没有人见过这个?您是否能够找出问题的根源?

Has anyone else ever encountered this? Were you able to isolate the source of the problem?

谢谢。

推荐答案

我弄清楚是什么触发了这个错误。当layoutFubviews和UIControlEventEditingChanged触发的方法调整textField的大小时,就会发生这种情况。

I figured out what triggers the bug. It happens when textField is resized both by layoutSubviews and by a method triggered by UIControlEventEditingChanged.

这篇关于iPad UITextField - 使用contentVerticalAlignment = UIControlContentVerticalAlignmentCenter调整帧大小时光标不居中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆