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
2010-09-15 19:05:09
Oh I gotcha so real time velocity using distance over time I suppose
Dick Savagewood
2010-09-16 11:34:43
The current time can be obtained by CACurrentMediaTime() in the QuartzCore framework. Then you can calculate velocity by distance and time.
Toro
2010-09-16 13:20:56