我在子UIView
内有一个点。我想找到CGPoint
相对于子视图的父UIView
的位置。我怎么得到它?
答案 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}
打印到控制台