Reputation: 372
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?
Upvotes: 1
Views: 1340
Reputation: 7704
CGPoint pointInSuperview = [superview convertPoint:pointInSubview fromView:subView];
Example:
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));
Prints out {70, 70}
to the console
Upvotes: 2