Find the coordinate of a subview in the coordinate space of a UIView higher in the view hierarchy
Problem
You have a subview nested in a view hierarchy and want to find the new coordinate of the subview in the coordinate system in another view.
Solution
Say you created a view hierarchy like this:
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, 20, 300, 300);
[self.view addSubview:subview1];
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30, 200, 200);
[superview addSubview:vsubview2];
To find the coordinate of subview in the view controller view coordinate system, use the following code:
CGPoint point = [subview1 convertPoint:subview2.frame.origin toView:self.view];
Reference
Written by Samuel Chow
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ios
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#