ios - 当前 View 中单元格的快速高度

标签 ios uitableview swift3

我在表格 View 中有几个单元格。现在在任何给定的时间点,我想计算 View 中单元格的当前高度,即如果它是 View 的 3/4,它应该返回 (cellheight)*3/4 高度。

我通过以下方式计算了当前 View :

let visibleRect = CGRect(origin: tableView.contentOffset, size: tableView.bounds.size)

现在当我停止滚动时,我想找到我在此处计算的特定索引路径的单元格的当前高度。

让 visiblePoint = CGPoint(x: visibleRect.midX, y: visibleRect.midY) 让 visibleIndexPath = tableView.indexPathForRow(at: visiblePoint)!

我希望我是清楚的。感谢您的帮助。

干杯!

最佳答案

要在获得所需的 indexPath 后获取 UITableViewCell 很容易,您需要调用此方法 self.tableView.cellForRow(at: indexpath) 之后您可以访问到你的单元格的框架,并与你之前计算的 visibleRect 相交,你必须拥有你需要的东西

      if let cell = self.tableView.cellForRow(at: indexpath) as? UITableViewCell
        {
            let intersection = cell.frame.intersection(visibleRect)
            debugPrint(intersection.size.height)
        }

关于ios - 当前 View 中单元格的快速高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45969691/

相关文章:

ios - 奇怪的 UIWebView 错误/行为

ios - 将 float 数组的数组转换为 UnsafeMutablePointer<UnsafeMutablePointer<Float>>

ios - Swift - 如何在表格 View 单元格中显示视频的缩略图捕获?

ios - 在 TableViewCell 内的 TextView 中快速点击背线和字母后,TableView 中重复多个部分

iphone - iOS - UITableView 在不同的 View Controller 中将 URL 推送到 UIWebView

ios - HKSampleQuery 不返回任何结果,即使有

ios - 将 MKMapView 放在 UITableView 后面

ios - 从特定行设置动态自定义单元格

ios - 将数据从 Marker 传递到其他 VC

ios - 由于关闭而导致对开始/结束外观转换的不平衡调用 - 不涉及任何转换或转场