Units / Sizes for UIScrollView Slowdown and Speed?

I am trying to get the scroll speed of a UIScrollView after the user has raised his finger so that I can trigger an event when the scroll speed drops below the threshold speed.

Apple's documentation states that scrollview speed units are in points , and I would assume that it would be per second (pts / s), for example, for the UIScrollView Delegate method - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset .

Therefore, I assumed that the units to slow down the scrolling would be dots per second per second (pts / s ^ 2) , but this does not seem to be the case.

Here are some sample parameters pulled out of the scrollable scroll view as soon as the panning gesture event ends (i.e. as soon as you lift your finger), pull from the methods - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset and - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView :

(initial displacement, target displacement, initial speed, final speed, braking, elapsed time) =

  • (364.0, 2664.5, 4.619940, 0, 0.998, 3.068916)
  • (2595.5, 3288.5, 1.398724, 0, 0.998, 2.485449).
  • (3094.5, 1907.0, -2.389578, 0, 0.998, 2.752163).
  • (143.0, 1275.5, 2.279252, 0, 0.998, 2.718653)

Where:

  • Start offset = scrollView.contentOffset.y as soon as the finger is raised
  • Target offset = targetContentOffset-> y as soon as the finger is raised, or scrollView.contentOffset.y when the scrollview is canceled.
  • Initial speed = speed. And as soon as the finger rises
  • Final speed = 0, because the scroll scroll scrolls until it stops naturally
  • Slow = scrollView.decelerationRate as soon as the finger is raised
  • Elapsed time = time between when finger is raised and when scrollview is suitable for resting
+4
source share
1 answer

The most important delegate method for your purposes is probably scrollViewDidScroll: because you just keep getting this message again and again, including during slowdown. Monitoring what is happening will be more useful to you than trying to calculate in advance. There are no useful "units to slow down scroll scrolling", i.e. You do not have any information that could allow you to calculate in advance the speed at each moment during braking. However, scrollViewWillEndDragging:withVelocity:targetContentOffset: tells you the speed now and the offset, which will look like a scroll when the speed is zero, and now you can request the offset so that you can choose the offset between the current offset and the final offset, and track the remaining the scroll part when it passes, in scrollViewDidScroll: to find out when this offset is transmitted. And, of course, you can assign a timestamp every time scrollViewDidScroll: is scrollViewDidScroll: , so with this and instantaneous offset along with recording from all previous calls, presto, there is your instantaneous speed.

+4
source

All Articles