如何获取在一个TableCell在iPhone上的TextField位置? [英] How to get the TextField position in a TableCell on iPhone?

查看:120
本文介绍了如何获取在一个TableCell在iPhone上的TextField位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是UI ...(我知道这是丑陋的...)橙色是一个视图,蓝色是表,灰色的是表单元格,最后,红色是表格单元格中的文本字段。我的问题很简单,我只想知道红色文本字段的位置...似乎表格单元格可以上下移动,所以,位置可以改变。所以,我不需要动态更新文本字段的位置,我只需要当用户点击文本字段时的位置,任何想法?感谢。

Here is the UI...(I know it is ugly...) The orange is a view, and the blue is the table, and the gray one is the table cell, lastly, the red is a textfield in a table cell. My question is simple, I just wanna to know the red text field position... Seems the table cell may move up and down, so, the position can be changed. So, I don't need to dynamic update the text field position, I just need the position when the user click the text field, any ideas? Thanks.

推荐答案

您可以使用可以在UIView或其派生类上使用的convetrPoint方法

you can make use of convetrPoint methods that can be used on an UIView or its derived classes

- (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view
- (CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view

p>

in you case, you'll need to do this:

- (void)textFieldDidBeginEditing(UITextField *)textField 
{
     CGPoint textFieldOriginInTableView = [textFiled convertPoint:textField.frame.origin toView:tableView];
     //or if you want it relative to the orangeView, your toView should be the orangeView
}

这篇关于如何获取在一个TableCell在iPhone上的TextField位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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