Is it possible to find out the final UIScrollView contentOffset before it finishes slowing down?

When the user “clicks” a UIScrollView , causing it to scroll with momentum, is there a way to figure out the final contentOffset before braking ends?

Basically, I would like to know that from scrollViewDidEndDragging:willDecelerate: from scrollViewDidEndDragging:willDecelerate: is the final scrollViewDidEndDragging:willDecelerate: instead of scrollViewDidEndDecelerating:

There is a float property called decelerationRate , which can be one part of the puzzle, but I still have to figure out what to do with it.

PS: I have pagingEnabled set to YES . In iOS 5 there is actually scrollViewWillEndDragging:withVelocity:targetContentOffset: but the document says that it does not start if pagingEnabled is YES

+4
source share
2 answers

As I noticed, max contentOffset can be calculated from the very beginning, it's just the difference between the frame size of scrollview contentSize and scrollview. I figured it out on y like this. maxOffsetY = scrollView.contentSize.height - scrollview.frame.size.height;

+7
source

It might be better, but from my head I would try this:

  • implement the scrollViewDidScroll: delegate method and get the firstOffsets first two times when this method is called (of course, they must be stored outside the method).

  • get the difference between the two readings of the content offset; it will be your delta.

  • now you can use the delta as the current speed of your scroll and your decelerationRate to determine how much it will scroll before the delta becomes 0. this value is + - (depending on the scroll) the second reading the content offset will be your “target scroll offset” .

make sure you verify that scrollview is actually slowing down before you apply this, and also make sure your final calculation is not “out of bounds” in terms of the size of the content.

hope this helps

+2
source

Source: https://habr.com/ru/post/1388689/


All Articles