计算View中的子View在View的superview中的坐标

来源:互联网 发布:羽毛球鹰眼算法 编辑:程序博客网 时间:2024/06/10 20:15


例如一个视图控制器的view中有一个UITableView,UITableView的某个cell中有个UITextField,想要得到UITextField在view中的位置,就要靠上面的两个方法了。


方法1、

CGRect rect = [self.view convertRect:textField.frame fromView:textField.superview];

或者

方法2、

CGRect rect = [textField.superview convertRect:textField.frame toView:self.view];

进行转换就可以了。


类似的方法还有:

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

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







0 0
原创粉丝点击