Coordinates of coordinates in UIView.

Source: Internet
Author: User

Coordinates of coordinates in UIView.
Coordinate Transformation in IOS -- UIView

 

// Convert the pixel point from the view where the point is located to the target view, and return the pixel value in the target view.

-(CGPoint) convertPoint :( CGPoint) point toView :( UIView *) view;

// Transfers the pixel point from the view to the current view and returns the pixel value in the current view.

-(CGPoint) convertPoint :( CGPoint) point fromView :( UIView *) view;

 

// Convert the rect view from the rect view to the target view, and return the rect in the target view.

-(CGRect) convertRect :( CGRect) rect toView :( UIView *) view;

// Switch the rect from the view to the current view, and return the rect in the current view.

-(CGRect) convertRect :( CGRect) rect fromView :( UIView *) view;

For example, convert the frame of subview (btn) in UITableViewCell to controllerA.

 

// There Is A UITableView in controllerA, multiple UITableVieCell lines in UITableView, and a button in cell.

// Implemented in controllerA:

CGRect rc = [cell convertRect: cell. btn. frame toView: self. view];

Or

CGRect rc = [self. view convertRect: cell. btn. frame fromView: cell];

// This rc is the rect of btn in controllerA

 

Or when btn is known:

 

CGRect rc = [btn. superview convertRect: btn. frame toView: self. view];

Or

CGRect rc = [self. view convertRect: btn. frame fromView: btn. superview];

Related Article

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.