Search code examples
objective-cuitableviewcell

Determine if UITableViewCell's position within screen


I'm trying to determine the position of a UITableViewCell with respect to the screen. For example, imagine I have a table view with 13 cells (and only 6 of them are visible on the screen, to see the rest you would have to scroll) and I would like to programmatically determine which one of my 13 cells is the last visible one at any point in time.

I am trying to create an effect like this:

TableView last cell

And as you scroll down, only the last cell is "blurred" (until you reach the end of the cells).

What I would like to do looks something like this:

if table has more cells that aren't visible at the moment
  last visible cell has a different colour
otherwise all cells have the same colour

Now, I can see a very trivial solution being to add a semi-transparent PNG that will achieve this effect but I would like to know if it is possible to do it programmatically.


Solution

  • The UITableView extends from UIScrollView, so you can get the contentOffset in order to know if it's at the end of its content using yourTableView.contentOffset and compare with contentSize.