Ios Can';无法使convertRect:从视图到工作
在我的Ios Can';无法使convertRect:从视图到工作,ios,swift,uiview,coordinates,frame,Ios,Swift,Uiview,Coordinates,Frame,在我的viewController中,我有一个带有自定义单元格的tableView。 在我的cellForRow:atIndexPath:方法中,我想根据我的视图控制器的坐标系访问特定单元格内显示的UIButton的位置(rect)。 这就是我认为它会起作用的方式: func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableVie
viewController
中,我有一个带有自定义单元格的tableView
。
在我的cellForRow:atIndexPath:
方法中,我想根据我的视图控制器的坐标系访问特定单元格内显示的UIButton的位置(rect
)。
这就是我认为它会起作用的方式:
func tableView(tableView: UITableView,
cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("cellId") as? MyCell
if cell != nil {
cell = MyCell(style: .Default, reuseIdentifier: "cellId")
}
let convertedFrame = view.convertRect(cell!.myButton.Frame, fromView: cell)
return cell!
}
它只给出按钮在其自身坐标系中的当前帧(0.0,0.0,44.0,44.0)
关于该方法的正确用法有什么线索吗?只需在单元格实际放入视图层次结构之前调用它即可。多亏了rmaddy指出了它。只需在单元格实际放置到视图层次结构之前调用它即可。感谢rmaddy的指出。改变
let convertedFrame = view.convertRect(cell!.myButton.Frame, fromView: cell)
到
改变
到
为什么要在
单元格中执行此操作?单元格甚至还没有添加到表中。这是有道理的。这可能是一个不好的地方。它不仅有意义,而且也起到了作用。非常感谢。为什么要在CellForRowatineXpath
中执行此操作?单元格甚至还没有添加到表中。这是有道理的。这可能是一个不好的地方。它不仅有意义,而且也起到了作用。非常感谢你。
let convertedFrame = view.convert(cell!.myButton.Frame, fromView: cell)