views:

68

answers:

1

I know how to get the contentOffset on movement for a UIScrollView, can someone explain to me how I can get an actual number that represents the current speed of a UIScrollView while it is tracking, or decelerating?

+1  A: 

You can see PageControl sample code about how to get the contentOffset of scrollview.

The contentOffset on movement can be obtained from UIScrollViewDelegate's method, named - (void)scrollViewDidScroll:(UIScrollView *)scrollView, by querying scrollView.contentOffset. Current speed can be calculated by delta_offset and delta_time.

  • Delta_offset = current_offset - pre_offset;
  • Delta_time = current_time - pre_time;
Toro
Oh I gotcha so real time velocity using distance over time I suppose
Dick Savagewood
The current time can be obtained by CACurrentMediaTime() in the QuartzCore framework. Then you can calculate velocity by distance and time.
Toro