【发布时间】:2015-02-20 04:34:49
【问题描述】:
我知道convertRect:toRect 是这里的关键,但我不知道如何调用它。我有我的单元格的子视图,我希望它在应用程序的整个窗口中的位置。
当我在其目标操作方法中点击此按钮(子视图)时,我需要知道这一点。我需要在单元格上调用convertRect:toRect 函数,我想,为了获得正确的坐标,但在这种方法中我没有引用单元格本身。
我会爬上 superview 层次结构吗?这看起来很恶心,因为我不完全确定我会得到什么,因为它嵌入在单元格的 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.
}
【问题讨论】:
-
@LyndseyScott 不,这是单元子视图上下文中的特定情况,在这种情况下获取视图的参考视图并不简单。
-
你为什么这么认为?
-
@LyndseyScott 因为这是我正在努力解决的问题?如果在上述情况下获取子视图所在单元格的引用很简单,请分享您的解决方案。
-
我同意 rmaddy 的解决方案。您不需要对单元格的引用......只需按钮。您无需将按钮转换为单元格的坐标系,然后将其转换为窗口的坐标系。一步完成。
标签: ios objective-c cocoa-touch uitableview uiview