I'm using a UIScrollView as the basis of a component that makes use of core animation. When the user swipes the view I would like to position elements according to the destination (resting) position of the scroll view. For this, I need to calculate the destination contentOffset of the UIScrollView in the scrollViewWillBeginDecelerating: method or similar.
The reason I need this is that I'll be using the destination contentOffset to animate views nested within the scrollview's contentView to their final position. I could of course set up an observer on the contentOffset or similar, but this would result in chaotic animation as the nested views would then update their positions multiple times during deceleration. I'd like this to happen just the once.
Is there a simple way to do this?
The point at which the origin of the content view is offset from the origin of the scroll view.
A floating-point value that determines the rate of deceleration after the user lifts their finger. We can assume that this rate indicates how much the scroll velocity will change after one millisecond (all UIScrollView values are expressed in milliseconds, unlike UIPanGestureRecognizer ).
There's a delegate method for this:
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset NS_AVAILABLE_IOS5(5_0);
According to the doc:
Called on finger up if the user dragged. velocity is in points/second. targetContentOffset may be changed to adjust where the scroll view comes to rest. not called when pagingEnabled is YES
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With