문제

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?

도움이 되었습니까?

해결책 2

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.

다른 팁

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;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top