gpt4 book ai didi

ios - 如何获得 subview 在我的 UITableViewCell 中相对于整个窗口的位置?

转载 作者:可可西里 更新时间:2023-11-01 04:25:06 28 4
gpt4 key购买 nike

我知道 convertRect:toRect 是这里的关键,但我不确定如何调用它。我有我的单元格的 subview ,我想要它在应用程序的整个窗口中的位置。

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

我是否攀登父 View 层次结构?这看起来很恶心,因为我不完全确定我会得到什么,因为它嵌入在单元格的 contentView 中,Apple 用他们的私有(private) subview 和诸如此类的东西做了一些古怪的事情。

代码:

@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];

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

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

// do your stuff

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

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

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

关于ios - 如何获得 subview 在我的 UITableViewCell 中相对于整个窗口的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27596565/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com