滚动时确定UITableViewCell的坐标 [英] Determine coordinates of a UITableViewCell while scrolling

查看:115
本文介绍了滚动时确定UITableViewCell的坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是让UITableViewCells在接近UITableView的边界时淡入/淡出并即将被覆盖/显示。

My goal is to have the UITableViewCells fade in/out when they are approaching the bounds of the UITableView and about to be covered/revealed.

我的方法一直在尝试是在滚动事件期间获取UITableViewCell的坐标。问题是每个细胞似乎都在0,0。我已经尝试将坐标转换为父表和视图,但它们仍然是0,0。

The approach I have been trying is to get the coordinates of the UITableViewCell during a scroll event. The problem is that every cell seems to be at 0,0. I have tried converting the coordinates to the parent table and view, but they still come out at 0,0.

所以一般来说,如果有人知道如何获得坐标,或根据他们的位置进出淡出UITableViewCells的更好方法,我将非常感谢您的任何建议。

So in general, if anyone knows a way to get the coordinates, or of a better way to go about fading UITableViewCells in and out based on their position, I would greatly appreciate any advice you may have.

感谢您的时间,
Joel

Thanks for your time, Joel

推荐答案

第一步是使用


CGRect rectInTableView = [tableView rectForRowAtIndexPath:indexPath];

将报告tableView中单元格的CGRect。但是,此值不会随tableView滚动而更改。它是相对于表格第一行的位置(而不是第一个可见行)。要在屏幕上获取单元格的位置,您必须使用

which will report the CGRect of a cell within the tableView. However, this value does not change as the tableView scrolls. It is the position relative to the first row of the table (and not the first visible row). To get the position of the cell on the screen you have to convert it to the superviews coordinate system using


将其转换为超视图坐标系CGRect rect = [ tableView convertRect:rectInTableView toView:[tableView superview]];

所以下面这一行都是这样做的

So the following line does it all


CGRect rect = [tableView convertRect:[tableView rectForRowAtIndexPath:indexPath] toView:[tableView superview]];

这篇关于滚动时确定UITableViewCell的坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆