// converts pixel point from view to target view, returns the pixel value in the target view -(Cgpoint) Convertpoint: (cgpoint) point toview: (UIView * ) view; // converts pixel point from view to the current view, returning the pixel value in the current View -(Cgpoint) Convertpoint: (cgpoint) point fromview: (UIView *) view; // converts a rect from the view of a rect to the target view, returning the Rect-(CGRect) Convertrect: (cgrect) rect toview: (UIView *) view in the target view ; // converts a rect from view to the current view, returning the Rect-(CGRect) Convertrect: (cgrect) rect fromview: (UIView *) view in the current view;
// there is a uitableview in the Controllera, there is a button on Uitableviecell,cell in UITableView . // implemented in Controllera: CGRect rc == [Self.view convertRect:cell.btn.frame Fromview:cell]; // This RC is a rect of btn in Controllera == [Self.view convertRect:btn.frame FromView:btn.superview];
Transfer excerpt from: http://blog.csdn.net/xuhuan_wh/article/details/8486337
Experience: Carefully listen to the reason, which view on the size, to which view to dig up the same size (in short, relative to the screen position unchanged). In short, a view is converted to another view, that is, the frame that will be converted directly to the outside of the convex or concave, to the target view of the corresponding size
eg
Uiscrollview *ss=[[Uiscrollview alloc]initwithframe:self.view.bounds]; Ss.backgroundcolor=[Uicolor Whitecolor]; Ss.contentsize=cgsizemake (Ss.frame.size.width, ss.frame.size.height*2); //Original ViewUIView *vv=[[uiview Alloc]initwithframe:cgrectmake ( -,580, -, +)]; Vv.backgroundcolor=[Uicolor Redcolor]; [SS ADDSUBVIEW:VV]; [Self.view ADDSUBVIEW:SS]; //Target ViewUIView *backgroundview=[[uiview Alloc]initwithframe:cgrectmake (0, -, the, -)]; Backgroundview.backgroundcolor=[Uicolor Browncolor]; [Self.view Addsubview:backgroundview]; //the size of the original view to be mapped to the target view to return its dimensionsCGRect rect=[VV convertRect:vv.bounds Toview:backgroundview]; NSLog (@"%@", Nsstringfromcgrect (rect)); CGRect Rect1=[Backgroundview convertRect:vv.bounds FROMVIEW:VV]; NSLog (@"%@", Nsstringfromcgrect (rect1));
Output Result: -- Geneva- to Ten: Geneva:10.301testconvertrect[1262:27344] {{ -,480}, { -, +}} -- Geneva- to Ten: Geneva:10.302testconvertrect[1262:27344] {{ -,480}, { -, +}}
Coordinate transformations in iOS development note--uiview (Convertrect)