samvermette / SVPullToRefresh

Give pull-to-refresh & infinite scrolling to any UIScrollView with 1 line of code.
http://samvermette.com/314
MIT License
4.82k stars 1.09k forks source link

scrollOffsetThreshold needs consider originalBottomInset? #300

Open sou1x0 opened 7 years ago

sou1x0 commented 7 years ago
- (void)scrollViewDidScroll:(CGPoint)contentOffset {
    if(self.state != SVInfiniteScrollingStateLoading && self.enabled) {
        CGFloat scrollViewContentHeight = self.scrollView.contentSize.height;
        CGFloat scrollOffsetThreshold = scrollViewContentHeight-self.scrollView.bounds.size.height;

        if(!self.scrollView.isDragging && self.state == SVInfiniteScrollingStateTriggered)
            self.state = SVInfiniteScrollingStateLoading;
        else if(contentOffset.y > scrollOffsetThreshold && self.state == SVInfiniteScrollingStateStopped && self.scrollView.isDragging)
            self.state = SVInfiniteScrollingStateTriggered;
        else if(contentOffset.y < scrollOffsetThreshold  && self.state != SVInfiniteScrollingStateStopped)
            self.state = SVInfiniteScrollingStateStopped;
    }
}

scrollOffsetThreshold should consider originalBottomInset. So I think scrollOffsetThreshold += self.originalBottomInset; should be inserted after CGFloat scrollOffsetThreshold = scrollViewContentHeight-self.scrollView.bounds.size.height;

Otherwise, when scrollview has bottom inset, supposed it's a positive number, and it currently reaches to the end, state will still be loading even though user scrolls up.