項(xiàng)目開發(fā)的時(shí)候設(shè)計(jì)圖是動(dòng)態(tài)瀏覽,仿新浪樣式的在做評(píng)論的時(shí)候坐標(biāo)點(diǎn)轉(zhuǎn)換有點(diǎn)問題嫡锌,當(dāng)時(shí)也不太理解有點(diǎn)犯暈歌懒,在此記錄一下
trend.gif
// 將像素point由point所在視圖轉(zhuǎn)換到目標(biāo)視圖view中躲庄,返回在目標(biāo)視圖view中的像素值
- (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view;
// 將像素point從view中轉(zhuǎn)換到當(dāng)前視圖中,返回在當(dāng)前視圖中的像素值
- (CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view;
// 將rect由rect所在視圖轉(zhuǎn)換到目標(biāo)視圖view中,返回在目標(biāo)視圖view中的rect
- (CGRect)convertRect:(CGRect)rect toView:(UIView *)view;
// 將rect從view中轉(zhuǎn)換到當(dāng)前視圖中,返回在當(dāng)前視圖中的rect
- (CGRect)convertRect:(CGRect)rect fromView:(UIView *)view;
例把UITableViewCell中的subview(btn)的frame轉(zhuǎn)換到 controllerA中
// controllerA 中有一個(gè)UITableView, UITableView里有多行UITableVieCell摹迷,cell上放有一個(gè)button
// 在controllerA中實(shí)現(xiàn):
CGRect rc = [cell convertRect:cell.btn.frame toView:self.view];
或
CGRect rc = [self.view convertRect:cell.btn.frame fromView:cell];
// 此rc為btn在controllerA中的rect
或當(dāng)已知btn時(shí):
CGRect rc = [btn.superview convertRect:btn.frame toView:self.view];
或
CGRect rc = [self.view convertRect:btn.frame fromView:btn.superview];