获取UIView级别的UITextField Y坐标? [英] Get UITextField Y coordinate on UIView level?
问题描述
目前,我在自定义单元格中有一个UITextField,我想在视图控制器视图(UIView)的水平上获取该UITextField的Y坐标。目前,我正在尝试执行以下操作:
Currently I have a UITextField in a custom cell and I want to get the Y coordinate of that UITextField on the level of the View Controller's view (UIView). Currently I am trying to do something like this:
if (thetextField.superview.superview.superview.frame.origin.y >= keyboardY) {
}
但似乎Y坐标实际上不是0时始终为0。有什么方法可以做到这一点?
But it seems that the Y coordinate is always 0 when it is in fact not. Is there any way to achieve this?
我这样做是因为我想检测UIKeyboard是否在UIView级别上阻塞了UITextField,以便我可以重新安排
I am doing this because I want to detect whether the UIKeyboard is blocking the UITextField on the UIView level so that I can re-arrange my cells accordingly.
谢谢!
推荐答案
检查<$ c 中的$ c> convertPoint:* 方法UIView文档。通过这些方法,您可以将点映射到其他视图坐标或从其他视图坐标映射。
Check convertPoint:*
methods in UIView documentation. These methods allow you to map point to or from other views coordinates.
假设 self
是视图控制器,该行在视图控制器的视图坐标中返回文本字段的原点:
Provided that self
is a view controller, this line returns text field's origin in view controller's view coordinates:
[thetextField convertPoint:thetextField.frame.origin toView:self.view];
您还可以使用 convertRect:*以类似的方式转换矩形。 code>方法。
You can also convert rects in a similar fashion using convertRect:*
methods.
这篇关于获取UIView级别的UITextField Y坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!