LoginSignup
4
3

More than 5 years have passed since last update.

UITableViewのCellが底まで表示されたかどうか判定する

Posted at

下記コードで実現しました。

extension UITableView {
    // indexPathsForVisibleRowsの内、そのCellの底が表示されているもののみ返します。
    func indexPathsForVisibleRowsOfDisplayedCellBottom() -> [IndexPath] {
        return self.indexPathsForVisibleRows?.filter { indexPath in
            let cellRect = self.rectForRow(at: indexPath)
            let cellBottomFromTableViewTop = cellRect.maxY
            let visibleTableViewBottomFromTableViewTop = self.contentOffset.y + self.frame.maxY
            if cellBottomFromTableViewTop <= visibleTableViewBottomFromTableViewTop {
                return true
            } else {
                return false
            }
        } ?? []
    }
}
4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3