Search code examples
iosswiftuitableviewpositionscrollview

How do I find UITableview scroll difference - swift


How to find the scroll difference of a UITableView. I need to find the difference of the Tableview content scroll from the tableview top position in swift

I tried the below code,

 func scrollViewDidScroll(_ scrollView: UIScrollView) {
            let contentOffset = tableview.frame.origin.y
            let maximumOffset = (contentOffset - scrollView.contentOffset.y)
            let dif  = maximumOffset
}

Solution

  • Contents offset of tableview, itself describe as difference between top of content to current scroll position.

    Try this and see:

    print(tableView.contentOffset)
    

    For more, see Apple Document - contentOffset

    contentOffset : The point at which the origin of the content view is offset from the origin of the scroll view.


    Also look at this refernce: