UIScrollView - reset without bindings

I want to return my content offset to UIScrollView if I am not dragging enough:

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(CGPoint *)targetContentOffset { self.endingOffset = scrollView.contentOffset; if(abs(verticalOffset) > [self cellHeight] / 9) { // If the user scrolled enough distance, attempt to scroll to the next cell ... } else if(self.nextCellOrigin.y != 0) { // The scroll view is still scrolling and the user didn't drag enough ... } else { // If the user didn't drag enough self.tableView.decelerationRate = UIScrollViewDecelerationRateNormal; (*targetContentOffset) = self.startingOffset; } } 

The code to return to the starting position is in the rest, and it always works. However, when I do not scroll enough and quickly make a gesture, he leans back. If I scroll a little and then hold this position a little longer than usual, it smoothly returns.

I did not find anything in the API link about how long the user touched UIScrollView, and even if I didn’t do it right away, I could use this to change the behavior of my returning code. I also tried scrolling the position using setContentOffset: animated: but that didn't seem to fix the twitch.

Any ideas?

+4
source share
1 answer

Have you tried to record the speed to find out how this happens when irritation occurs?

EDIT

What you can try to do is implement these two delegation methods of scrollView instead of the willEndDragging method. This solution will give a different view of scrollView, but try it.

Fill the checkOffset method checkOffset all the necessary logic.

 - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate { // if scrollView contentOffset reached its final position during scroll, it will not decelerate, so you need a check here too if (!decelerate) { [self checkOffset]; } } - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { [self checkOffset]; } - (void)checkOffset { CGPoint newOffset; ... // Do all the logic you need to move the content offset, then: ... [self.scrollView setContentOffset:newOffset animated:YES]; } 

EDIT # 2: Maybe you can achieve a better result if you also add this to my solution. Try it;)

 - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(CGPoint *)targetContentOffset { // This should force the scrollView to stop its inertial deceleration, by forcing it to stop at the current content offset *targetContentOffset = scrollView.contentOffset; } 
+5
source

All Articles