1

It appears self.decelerating and self.dragging are not reliable during an overridden layoutSubviews call. For example, they are occasionally both true, which is obviously not possible.

Is there a reliable way to get whether the UIScrollView is decelerating in layoutSubviews?

Max
  • 2,760
  • 1
  • 28
  • 47

2 Answers2

0

I've never had any issues with the UIScrollView protocol methods being unreliable. Is it possible for you to manage whatever your doing currently in layoutSubviews from another delegate class? Like a parent view, or something?

Then you could listen for the delegate methods with (potentially) more reliability.

#pragma mark UIScrollViewDelegate

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
  if (self.scrollViewDecelerating)
  {
    // stuff...
  }
}

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
{
  self.scrollViewDecelerating = YES;
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
  self.scrollViewDecelerating = NO;
}
Kyle Truscott
  • 1,537
  • 1
  • 12
  • 18
0

Having an instance variable set like so fixed it:

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView {
    _decelerating = YES;
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    _decelerating = NO;
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
    _decelerating = NO;
}

The issue is if you start dragging while it's decelerating, self.decelerating is not unset. The above fixes that by taking into account scrollViewWillBeginDragging.

Max
  • 2,760
  • 1
  • 28
  • 47