我有UIView1,它持有一个子UIView2
,UIView2
持有一个子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];