I am attempting to modify the contentOffset of my scroll within the following delegate method:
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
I have tried both of the following:
[UIView animateWithDuration:.2 animations:^ {
[scrollView setContentOffset:CGPointZero animated:NO];
}];
and
[UIView animateWithDuration:.2 animations:^ {
CGRect svBounds = self.bounds;
svBounds.origin.y = 0;
self.bounds = svBounds;
}];
The problem is that although this changes the offset right away (proven by logs after the animation is complete), it doesn't change the visible scroll location. This is further proven by subsequent delegate methods of my scroll view which indicate that the bounds have indeed not changed at all. Meaning that the y location is not 0.
Is it forbidden to change the content offset in this particular delegate method? If so, when is it possible for me to change the offset? I'm trying to perform an animation of returning the visible scroll area to the top once the user finishes dragging (after a certain amount).
Thanks!
what i did eventually is dispatching again to the main queue. meaning:
and it actually works :-)
Depending on the effect you are trying to achieve, you may have more luck with this delegate method:
You can choose what target content offset you want to use for the scroll view to decelerate to once the user stops dragging.
You should "nil" your scrollView delegate before animation, set content offset in
scrollViewDidEndDragging:willDecelerate:
will cause repeat delegation.