1.將像素point由point所在視圖轉(zhuǎn)換到目標(biāo)視圖view中瘾敢,返回在目標(biāo)視圖view中的像素值
- (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view;
2.將像素point從view中轉(zhuǎn)換到當(dāng)前視圖中,返回在當(dāng)前視圖中的像素值
- (CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view;
3.將rect由rect所在視圖轉(zhuǎn)換到目標(biāo)視圖view中尿这,返回在目標(biāo)視圖view中的rect
- (CGRect)convertRect:(CGRect)rect toView:(UIView *)view;
4.將rect從view中轉(zhuǎn)換到當(dāng)前視圖中簇抵,返回在當(dāng)前視圖中的rect
- (CGRect)convertRect:(CGRect)rect fromView:(UIView *)view;
栗子1:
條件: ?把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];
栗子2:
要求: ?把一個(gè)rect從fromView坐標(biāo)系轉(zhuǎn)換到方法調(diào)用的view的坐標(biāo)系下射众。
CGRect rect2 = [self.view convertRect:imageView.frame fromView:imageView.superview];
imageViewController.frame = rect2;
CGRect rect1 = [imageView.superview convertRect:imageView.frame toView:self.view];
NSLog(@"\n%@-----%@", NSStringFromCGRect(rect1), NSStringFromCGRect(rect2));