IOS-- UIView中的座標轉換



// 將像素pointpoint所在視圖轉換到目標視圖view中,返回在目標視圖view中的像素值

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

// 將像素pointview中轉換到當前視圖中,返回在當前視圖中的像素值

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


// rectrect所在視圖轉換到目標視圖view中,返回在目標視圖view中的rect

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

// rectview中轉換到當前視圖中,返回在當前視圖中的rect

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


UITableViewCell中的subview(btn)frame轉換 controllerA

// controllerA 中有一個UITableView, UITableView裏有多行UITableVieCell,cell上放有一個button

// controllerA中實現:

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

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

// rcbtncontrollerA中的rect


或當已知btn時:

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

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

發佈了11 篇原創文章 · 獲贊 5 · 訪問量 144萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章