Getting the exact location of a UITableViewCell

后端 未结 9 589
滥情空心
滥情空心 2021-01-30 20:10

Given a UITableView, how can I find the location of a specific UITableViewCell? In other words, I want to get its frame relative to my iPhone screen, n

9条回答
  •  梦毁少年i
    2021-01-30 21:01

    Swift 3

    Relative to the tableView:

    let rect = self.tableView.rectForRow(at: indexPath)
    

    Relative to the Screen:

    If you only know the cell,

    if let indexPath = tableView.indexPath(for: cell) {
         let rect = self.tableView.rectForRow(at: indexPath)
         let rectInScreen = self.tableView.convert(rect, to: tableView.superview)
    }
    

    If you know the indexPath then don't need call the if statement.

提交回复
热议问题