获取CGPoint(在子视图中)的位置,W.R.T parentView - ObjectiveC

时间:2013-05-28 09:34:54

标签: objective-c uiview

我在子UIView内有一个点。我想找到CGPoint相对于子视图的父UIView的位置。我怎么得到它?

1 个答案:

答案 0 :(得分:2)

CGPoint pointInSuperview = [superview convertPoint:pointInSubview fromView:subView];

示例:

UIView *subView = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];
[self.view addSubview:subView];

CGPoint pointInSubview = CGPointMake(20, 20);
CGPoint pointInSuperview = [self.view convertPoint:pointInSubview fromView:subView];
NSLog(@"%@", NSStringFromCGPoint(pointInSuperview));

{70, 70}打印到控制台