Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
}
like image 532
Vineesh TP Avatar asked Apr 04 '18 15:04

Vineesh TP


2 Answers

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:

  • Understanding of Content Offset
like image 107
Krunal Avatar answered Oct 03 '22 05:10

Krunal


A UITableView is a subclass of UIScrollView, so it has a contentOffset property.

When you're learning about a class, remember to check it's parent class. Sometimes the properties/methods you're looking for are in the parent. (I'm as guilty of forgetting to check the interface of parent classes as anybody.)

like image 30
Duncan C Avatar answered Oct 03 '22 06:10

Duncan C