iOS-UIView中的坐標(biāo)轉(zhuǎn)換

UIView的坐標(biāo)轉(zhuǎn)換

// 將point由point所在視圖轉(zhuǎn)換到目標(biāo)視圖view中,返回在目標(biāo)視圖view中的CGPoint
-(CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view;

// 將point從view中轉(zhuǎn)換到當(dāng)前視圖中,返回在當(dāng)前視圖中的CGPoint
-(CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view;

// 將rect由rect所在視圖轉(zhuǎn)換到目標(biāo)視圖view中,返回在目標(biāo)視圖view中的CGRect
-(CGRect)convertRect:(CGRect)rect toView:(UIView *)view;

// 將rect從view中轉(zhuǎn)換到當(dāng)前視圖中,返回在當(dāng)前視圖中的CGRect
-(CGRect)convertRect:(CGRect)rect fromView:(UIView *)view;

舉個(gè)??

UITableViewCell中某一個(gè)label的frame轉(zhuǎn)換到controller中

// controller 中有一個(gè)UITableView, UITableView里有多行UITableVieCell,cell上放有一個(gè)UILabel
// 在controller中實(shí)現(xiàn):

  • CGRect labelRect = [cell convertRect:cell.label.frame toView:self.view];
  • CGRect labelRect = [self.view convertRect:cell.label.frame fromView:cell];

// 此labelRect為label在controller中的CGRect

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容