最近有個需求甲抖,需求如下:vc下有一個tableview和一個button,這兒以568作為屏幕高心铃。tableview的frame為(0,0,320,568);button的frame為(0,20,320,60),tableview在最上層准谚,蓋住button,然后設(shè)置tab的ContentInset為(100,0,0,0)去扣,tab的背景色為透明柱衔,試問,當(dāng)我點擊button的時候我應(yīng)該怎么樣才能拿到button 的點擊事件愉棱?唆铐?
因為這個我是用坐標(biāo)轉(zhuǎn)換來做的,所以這里就記錄一下坐標(biāo)轉(zhuǎn)換奔滑。
//將像素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;
或當(dāng)已知viewA時:
[self convertPoint:point toView:viewA]
或
[viewA convertPoint:point fromView:self]
//將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(viewA)的frame轉(zhuǎn)換到controllerA中
// controllerA 中有一個UITableView, UITableView里有多行UITableVieCell,cell上放有一個viewA
//在controllerA中實現(xiàn):
CGRect rect = [cell convertRect:cell.viewA.frame toView:self.view];
或
CGRect rect = [self.view convertRect:cell.viewA.frame fromView:cell];
//此rect為viewA在controllerA中的rect
或當(dāng)已知viewA時:
CGRect rect = [viewA.superview convertRect:viewA.frame toView:self.view];
或
CGRect rect = [self.view convertRect:viewA.frame fromView:viewA.superview];