我如何得到我的UITableViewCell中的子视图相对于整个窗口的位置?

我知道convertRect:toRect是这里的关键,但我不知道如何调用它。 我有我的细胞的子视图,我希望它在应用程序的整个窗口中的位置。

我需要知道这一点,当我点击这个button(子视图)的目标行动方法。 我需要调用单元格的convertRect:toRect函数,我想,为了得到正确的坐标,但是在这个方法中,我没有参考单元格本身。

我是否爬上超视图层次? 这看起来很糟糕,因为我不完全确定我会得到什么,因为它embedded在单元格的contentView中,而苹果用他们的私人子视图和其他东西做了一些古怪的事情。

码:

 @IBAction buttonPressed(sender: UIButton) { // This button got the callback that it was pressed. It's in a cell. I need to convert its rect to that of the window here. I need the coordinate system it's calculated from (the cell) which I'm not sure of how to easily do in a target action callback. } 

其实很简单:

 CGRect windowRect = [someSubview convertRect:someSubview.bounds toView:nil]; 

假设你有一个button处理程序:

 - (void)someButtonHandler:(id)sender { UIButton *button = sender; // do your stuff CGRect windowRect = [button convertRect:button.bounds toView:nil]; } 

当然,如果你的方法设置为:

 - (void)someButtonHandler:(UIButton *)button { }