Scrolling indicator gets stuck when bounce is disabled for UIScrollView

I have this problem and I can not find any mention of it anywhere.

Basically, if I turn off bouncing in UIScrollView (derivatives like UITableView also affect it), I can make the scroll indicator get stuck if the user scrolls up and then tries to continue scrolling with a different gesture using a quick swipe.

As soon as this happens, the scroll indicator will not disappear unless the user scrolls again or scrolls. The biggest problem is that scrollview will capture this click, and therefore, if you try to click on a table cell, nothing will happen the first time.

I tested this only with the barebones app on both my device and the simulator, and it seems to be a common problem with UIScrollView and disabling bouncing; however, as I said, I cannot find another mention of this on the Internet.

Is this just a mistake? Is this expected behavior? Am I doing something wrong? If this is a mistake, does anyone know of a workaround or a fix?

+8
source share
2 answers

Have you added a highlight gesture for your scroll if you do not try to add it?

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(resignsKeyboard)]; [self.scrollView addGestureRecognizer:singleTap]; singleTap.numberOfTapsRequired = 1; singleTap.delegate = self; 

Add a UIGestureRecognizerDelegate delegate to your interface file, and then implement the delgate method of gesture clicking

 -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { if (self.scrollView.superview != nil) { if ([touch.view isKindOfClass:[UIButton class]]||[touch.view.superview.superview isKindOfClass:[UITableViewCell class]]||[touch.view.superview.superview.superview isKindOfClass:[UITableViewCell class]]||[touch.view.superview isKindOfClass:[UITableViewCell class]]) // we touched our control surface { return NO; // ignore the touch } } return YES; // handle the touch } 

// To perform other scroll actions, such as resigning the keyboard, use if necessary

 -(void) resignsKeyboard { [self.view endEditing:YES]; [self.scrollView setContentOffset:CGPointMake(0,0) animated:YES]; } 
0
source

In my case, I had two UIScrollView , one nested in the other. When the inner scroll view reached the top, I forced contentOffset.y to 0 (zero). This caused the unwanted scroll view behavior described in this question .

For the fix, contentOffset.y value of contentOffset.y -1 , which allowed the scroll view to return to 0 naturally (by itself), and the -1 behavior was rejected.

Hope this helps others βœ‹

0
source

All Articles