怎么獲取view在父類中的frame, 或者說 父類UIView中SubView的坐標(biāo)怎么轉(zhuǎn)換成在父類UIView中的坐標(biāo)
// 將像素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 中有一個UITableView, UITableView里有多行UITableVieCell贬蛙,cell上放有一個button
// 在controllerA中實現(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時:
CGRect rc = [btn.superview convertRect:btn.frame toView:self.view];
或
CGRect rc = [self.view convertRect:btn.frame fromView:btn.superview];
子控件位置轉(zhuǎn)換成父控件的位置
CGRect focusFrame = [_scrollView convertRect:_joinView.frametoView:self.view];
這里_scrollView是self.view的子控件
_joinView是_scrollView的子控件雨女,這里是計算出_joinView在self.view的位置,
當(dāng)然還有其他類似的方法
[view convertPoint:<#(CGPoint)#> fromView:<#(UIView *)#>]
[view convertPoint:<#(CGPoint)#> toView:<#(UIView *)#>]
[self.view convertRect:<#(CGRect)#> fromView:<#(UIView *)#>]
[self.view convertRect:<#(CGRect)#> toView:<#(UIView *)#>]