The coordinate system can be switched between different view by the following function, as below is the conversion of the current view to Parentview coordinates (a matrix conversion)
CGRect parentrect = [CurrentView convertRect:blankImageView.bounds ToView:self.superview];
(Self.view on Viewa and viewb two views btn on Viewa)
Absolute rect =[viewa.superview convertRect:btn.frame Fromview:viewa]; Relative to the Self.view, which is relative to the screen.
Relative rect =[viewa convertRect:btn.frame TOVIEW:VIEWB]
UIView *VIEWC = [UIView new]; Viewc.backgroundcolor = [Uicolor graycolor]; viewc.frame =< c4> rect; [Viewb ADDSUBVIEW:VIEWC];
Get the coordinates of the current position of the btn.frame relative to the VIEWB.
// converts pixel point from view to target view, returns the pixel value in the target view -(Cgpoint) Convertpoint: (cgpoint) point toview: (UIView *) view; // converts a 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 in the target view -(CGRect) Convertrect: (cgrect) rect toview: (UIView *) view; // converts a rect from view to the current view, returning a rect in the current view
Example converts a frame of subview (BTN) in UITableViewCell to Controllera
// there is a uitableview in the Controllera, there is a button on Uitableviecell,cell in UITableView . // implemented in Controllera: CGRect rc = [cell convertRect:cell.btn.frame ToView:self.view]; or = [Self.view convertRect:cell.btn.frame Fromview:cell]; // This RC is a rect of btn in Controllera or when known btn: = [Btn.superview convertRect:btn.frame ToView:self.view]; or = [Self.view convertRect:btn.frame FromView:btn.superview];
IOS view switching between different views (for Convertrect: Some understanding of functions)