1

I have a point inside a subUIView. I want to find the location of that CGPoint with respect to the subview's parent UIView. How do I get it?

4

1 回答 1

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}到控制台

于 2013-05-28T09:40:55.033 回答