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


例如一个视图控制器的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







猜你喜欢

转载自blog.csdn.net/xuexixiaoshizhe/article/details/47039741