Coordinate transformations in iOS development note--uiview (Convertrect)

Source: Internet
Author: User

// 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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.