cell在屏幕中的位置
CGRectrectInTableView = [tableView rectForRowAtIndexPath:indexPath];//獲取cell在tableView中的位置CGRectrectInSuperview = [tableView convertRect:rectInTableView toView:[tableView superview]];
//方法- (CGRect)convertRect:(CGRect)rect toView:(UIView *)view;意思為將rect由rect所在視圖轉(zhuǎn)換到目標(biāo)視圖view中,返回在目標(biāo)視圖view中的rect,所以此句含義為:將cell在 tableView中的位置,由在tableView中的位置,轉(zhuǎn)換到tableView的父視圖(即self.view)中,并返回在self.view中的位置
另外,注意:想要獲取哪個cell的位置,indexPath就是哪個cell的indexPath,不要認(rèn)為有indexPath,就寫在- (UITableViewCell)tableView:(UITableView)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath方法中,應(yīng)該根據(jù)情況寫在合適的方法中,方法中沒有indexPath時,可以通過傳值代理之類的將之獲取到
cell中的控件(比如按鈕)在屏幕中的位置
UIWindow* window = [UIApplicationsharedApplication].keyWindow;CGRectrect1 = [sender convertRect:sender.framefromView:self.contentView];//獲取button在contentView的位置CGRectrect2 = [sender convertRect:rect1 toView:window];
原文鏈接:http://blog.csdn.net/ideaspress/article/details/47002895