pronebird / UIScrollView-InfiniteScroll

UIScrollView ∞ scroll category
MIT License
1.06k stars 148 forks source link

setContentOffset/scrollRectToVisible works unexpected after infinite scroll handler invoked at least once #76

Open Aft3rmathpwnz opened 5 years ago

Aft3rmathpwnz commented 5 years ago

The same behaviour can be noticed in demo app: add leftNavBarItem "Up", which will handle tap as tableView.setContentOffset(CGPoint(x: 0, y: -tableView.contentInset.top), animated: true) for example. Scroll by finger to bottom, wait till fetching will be completed, then tap "Up" button and you will end up with messed contentOffset. When I was debugging this in my project I noticed that swizzled method pb_setContentOffset wasn't logging last values, i.e. contentSize was (375, 12000), contentOffset was (0, 6000), after setContentOffset (or scrollRectToVisivle with (0,0,tableView.frame.size.width, 1.0)) final log in pb_setContentOffset was like ±600, and it was the exact position according to View Debugger. Second tap when have an offset of 600 is driving contentOffset to be correct. Any thoughts or workarounds?

pronebird commented 5 years ago

That's super weird. Do you think it can be related to contentInsetAdjustmentBehavior introduced in iOS 11? I haven't got time to fix that :/

Aft3rmathpwnz commented 5 years ago

I don't think so, I can see the same behavior in iOS 10 too

Aft3rmathpwnz commented 5 years ago

What else I can check to probably fix it?

Aft3rmathpwnz commented 5 years ago

Another idea is that something is being set up/off incorrectly on the "load more" action when reaching the bottom of content because this contentOffset wrong value has a cumulative nature (i.e. if we "Go up" after only one "load more" we will have 150px mistake, if after 2 - 330, then 479 etc.) and after reaching contentOffset 0;0 by gesture or manuallty tapping "Go up" 2 times then we will have to perform "load more" to make this bug appear again.

pronebird commented 5 years ago

@Aft3rmathpwnz trying to reproduce this. I'll get back to you later.

Yeah alright I can reproduce this too. I'll add more logging around to see what and when breaks the animation.

Aft3rmathpwnz commented 5 years ago

@pronebird Hey, the reason behind it was that I have a table view and was trying to set contentOffset instead of scrollToRowAtIndexPath:atScrollPosition:animated:. With the last one everything's okay (I got hint from your sources' comment). Why is this happening from technical perspective, do you know?

pronebird commented 5 years ago

@Aft3rmathpwnz I don't exactly recall, since it's been a long time ago when I touched this code last time. But perhaps it has something to do with self-sizing cells and auto-layout. Try disabling self-sizing cells in demo and see if you can reproduce the same issue.