Skip to content

Instantly share code, notes, and snippets.

@cybersamx
Created August 6, 2014 17:58
Show Gist options
  • Save cybersamx/d94f854b8f714ba56b00 to your computer and use it in GitHub Desktop.
Save cybersamx/d94f854b8f714ba56b00 to your computer and use it in GitHub Desktop.
To find the coordinate of subview in the view controller view coordinate system.
// Create nested subviews. self.view > subview1 > subview2
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:subview2];
// To find the coordinate of subview in the view controller view coordinate system.
CGPoint point = [subview1 convertPoint:subview2.frame.origin toView:self.view];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment