Here is a variation of the above implemented in Swift:
var cellRect = tableView.rectForRowAtIndexPath(indexPath)
if let superview = tableView.superview {
let convertedRect = tableView.convertRect(cellRect, toView:superview)
let intersect = CGRectIntersection(tableView.frame, convertedRect)
let visibleHeight = CGRectGetHeight(intersect)
}
visibleHeight
being the part of the cell that is visible. One further step can be added to calculate the ratio - between zero and one - of the cell that is visible:
var cellRect = tableView.rectForRowAtIndexPath(indexPath)
if let superview = tableView.superview {
let convertedRect = tableView.convertRect(cellRect, toView:superview)
let intersect = CGRectIntersection(tableView.frame, convertedRect)
let visibleHeight = CGRectGetHeight(intersect)
let cellHeight = CGRectGetHeight(cellRect)
let ratio = visibleHeight / cellHeight
}
To change view appearances depending on visibility - as the question states above - this code should be included in the table view's UIScrollView superclass delegate, UIScrollViewDelegate method scrollViewDidScroll.
However, that will only affect cells as they scroll. Cells already visible would not be affected. For those, the same code should be applied in the UITableViewDelegate method didEndDisplayingCell.