From 1d40d1733f632e105dbcd3fb0b536f7454b572ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B5=E5=AD=90=E5=92=96=E5=95=A1?= Date: Tue, 5 Nov 2013 17:09:45 +0800 Subject: [PATCH] fix bug: pull refresh action will tragger infinite view when the content height is less than the frame height --- Demo/SVPullToRefreshDemo/SVViewController.m | 6 ++++-- SVPullToRefresh/UIScrollView+SVInfiniteScrolling.m | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Demo/SVPullToRefreshDemo/SVViewController.m b/Demo/SVPullToRefreshDemo/SVViewController.m index 10c1aaa1..9588b51c 100644 --- a/Demo/SVPullToRefreshDemo/SVViewController.m +++ b/Demo/SVPullToRefreshDemo/SVViewController.m @@ -26,24 +26,26 @@ - (void)viewDidLoad { // setup pull-to-refresh [self.tableView addPullToRefreshWithActionHandler:^{ + NSLog(@"refresh top"); [weakSelf insertRowAtTop]; }]; // setup infinite scrolling [self.tableView addInfiniteScrollingWithActionHandler:^{ + NSLog(@"refresh bottom"); [weakSelf insertRowAtBottom]; }]; } - (void)viewDidAppear:(BOOL)animated { - [tableView triggerPullToRefresh]; +// [tableView triggerPullToRefresh]; } #pragma mark - Actions - (void)setupDataSource { self.dataSource = [NSMutableArray array]; - for(int i=0; i<15; i++) + for(int i=0; i<4; i++) [self.dataSource addObject:[NSDate dateWithTimeIntervalSinceNow:-(i*90)]]; } diff --git a/SVPullToRefresh/UIScrollView+SVInfiniteScrolling.m b/SVPullToRefresh/UIScrollView+SVInfiniteScrolling.m index e43490ec..45b326ff 100644 --- a/SVPullToRefresh/UIScrollView+SVInfiniteScrolling.m +++ b/SVPullToRefresh/UIScrollView+SVInfiniteScrolling.m @@ -192,6 +192,9 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N } - (void)scrollViewDidScroll:(CGPoint)contentOffset { + if (contentOffset.y<=0) {//negative means pull + return; + } if(self.state != SVInfiniteScrollingStateLoading && self.enabled) { CGFloat scrollViewContentHeight = self.scrollView.contentSize.height; CGFloat scrollOffsetThreshold = scrollViewContentHeight-self.scrollView.bounds.size.height;