如何获得父视图控制器目标 c 中的 x,y 位置



我有UIView1,它持有一个子UIView2UIView2持有一个子UILabel

是否有可能根据UIView1获得该UILabel的 x,y .

我试图与convertPoint合作,但没有成功。

试试这个!

CGRect NewFrame = [View1 convertRect:YourLabel.frame fromView:View2];

根据第一个视图检查您的新帧。

CGFloat Xposition = NewFrame.frame.origin.x; 
CGFloat Yposition = NewFrame.frame.origin.y;
UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 400, 400)];
UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 50, 50)];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 10, 10)];
[view1 addSubview:view2];
[view2 addSubview:label];

CGRect rect = [label.superview convertRect:label.frame toView:view1];

最新更新