Projects often have requirements related to obtaining the coordinate dimensions of individual controls or attempts to be in their parent view. The control can be obtained in the fixed coordinate system of the superview in the following two ways

CGRect rect=[cell convertRect:cell.textView.bounds toView:self.tableView];
Copy the code
CGRect rect = [self.tableView convertRect:cell.textView.bounds fromView:cell];
Copy the code

hierarchy

cell.textView->

cell->

Self. tableView(superview)


If you want to display or perform some operations when the page slides to a certain control or control slides to a certain coordinate point of the window page, you can set toView as window, and then the coordinate displayed in scrollViewDidScroll is the coordinate of the control on the current page

-(void)scrollViewDidScroll:(UIScrollView *)scrollView { UIWindow * window=[[[UIApplication sharedApplication] delegate] window]; CGRect rect=[self.textView convertRect:self.textView.bounds toView:window]; if (rect.origin.y<SCREEN_HEIGHT) { [self.textView becomeFirstResponder]; }}Copy the code

Convert pixels
ConvertPoint :(CGPoint)point toView:(UIView *)view; // convert pixel point from point view to target view, return the pixel value in target view - (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view; // convert pixel point fromView to current view, return the pixel value in current view - (CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view;Copy the code

[fromView convertPoint:point toView:toView];

[toView convertPoint:point fromView:fromView];

Convert the Rect
Rect - (CGRect)convertRect:(CGRect)rect toView:(UIView *)view; Rect - (CGRect)convertRect:(CGRect)rect fromView:(UIView *)view;Copy the code

[fromView convertRect:rect toView:toView];

[toView convertRect:rect fromView:fromView];