如何在整个窗口中获取UITableViewCell中子视图的位置?

时间:2014-12-22 04:24:10

标签: ios objective-c cocoa-touch uitableview uiview

我知道convertRect:toRect是关键所在,但我不确定如何调用它。我有我的单元格的子视图,我希望它在应用程序的整个窗口中的位置。

当我在目标操作方法中点击此按钮(子视图)时,我需要知道这一点。我需要在单元格上调用convertRect:toRect函数,以获得正确的坐标,但在这种方法中,我没有引用单元格本身。

我是否攀登超级视图层次结构?这看起来很糟糕,因为我并不完全确定我会得到什么,因为它嵌入在单元格的contentView中,而且Apple通过私人子视图和诸如此类的东西做了一些古怪的东西。

代码:

@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.
}

2 个答案:

答案 0 :(得分:8)

实际上很简单:

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

假设你有一个按钮处理程序:

- (void)someButtonHandler:(id)sender {
    UIButton *button = sender;

    // do your stuff

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

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

,则更容易
- (void)someButtonHandler:(UIButton *)button {
}

答案 1 :(得分:0)

快速解决方案
with bar_agg as ( select foo.goober ,sum(bar.value) bar_value_sum from foo join bar on bar.foo_id = foo.id group by foo.goober ) ,foo_agg as ( select foo.goober ,sum(foo.value) foo_value_sum from foo group by foo.goober ) select foo.goober ,foo_value_sum ,bar_value_sum ,foo_value_sum - bar_value_sum foo_bar_diff from foo_agg foo left join bar_agg bar on bar.goober = foo.goober order by foo.goober 的帧转换为myView

中的相应帧
parentView