From ada9e248aea75532eb95271279b933f3a2490369 Mon Sep 17 00:00:00 2001 From: MJ Lee Date: Tue, 14 Jun 2016 20:51:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=80=E4=BA=9B=E6=AE=8B=E7=95=99=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.用async+mainQueue替代endRefreshing的0.1s延迟问题 2.完善:圈圈控件根据文字长短变换位置 --- MJRefresh.podspec | 2 +- MJRefresh/Base/MJRefreshBackFooter.m | 24 ++++++------------- MJRefresh/Base/MJRefreshComponent.m | 4 +++- MJRefresh/Base/MJRefreshHeader.m | 10 +++----- .../Second/MJCollectionViewController.m | 2 +- 5 files changed, 15 insertions(+), 27 deletions(-) diff --git a/MJRefresh.podspec b/MJRefresh.podspec index d621a688..6f35fa64 100644 --- a/MJRefresh.podspec +++ b/MJRefresh.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'MJRefresh' - s.version = '3.1.4' + s.version = '3.1.5' s.summary = 'An easy way to use pull-to-refresh' s.homepage = 'https://github.com/CoderMJLee/MJRefresh' s.license = 'MIT' diff --git a/MJRefresh/Base/MJRefreshBackFooter.m b/MJRefresh/Base/MJRefreshBackFooter.m index 0ffc5e92..71d43617 100644 --- a/MJRefresh/Base/MJRefreshBackFooter.m +++ b/MJRefresh/Base/MJRefreshBackFooter.m @@ -122,29 +122,19 @@ - (void)setState:(MJRefreshState)state } } -#pragma mark - 公共方法 - (void)endRefreshing { - if ([self.scrollView isKindOfClass:[UICollectionView class]]) { - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [super endRefreshing]; - }); - } else { - [super endRefreshing]; - } + dispatch_async(dispatch_get_main_queue(), ^{ + self.state = MJRefreshStateIdle; + }); } -- (void)noticeNoMoreData +- (void)endRefreshingWithNoMoreData { - if ([self.scrollView isKindOfClass:[UICollectionView class]]) { - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [super noticeNoMoreData]; - }); - } else { - [super noticeNoMoreData]; - } + dispatch_async(dispatch_get_main_queue(), ^{ + self.state = MJRefreshStateNoMoreData; + }); } - #pragma mark - 私有方法 #pragma mark 获得scrollView的内容 超出 view 的高度 - (CGFloat)heightForContentBreakView diff --git a/MJRefresh/Base/MJRefreshComponent.m b/MJRefresh/Base/MJRefreshComponent.m index 7e08c0b4..9c4dc2d0 100644 --- a/MJRefresh/Base/MJRefreshComponent.m +++ b/MJRefresh/Base/MJRefreshComponent.m @@ -170,7 +170,9 @@ - (void)setState:(MJRefreshState)state { _state = state; - [self setNeedsLayout]; + dispatch_async(dispatch_get_main_queue(), ^{ + [self setNeedsLayout]; + }); } #pragma mark 进入刷新状态 diff --git a/MJRefresh/Base/MJRefreshHeader.m b/MJRefresh/Base/MJRefreshHeader.m index 65bb5fb5..ed3ae766 100644 --- a/MJRefresh/Base/MJRefreshHeader.m +++ b/MJRefresh/Base/MJRefreshHeader.m @@ -137,13 +137,9 @@ - (void)setState:(MJRefreshState)state #pragma mark - 公共方法 - (void)endRefreshing { - if ([self.scrollView isKindOfClass:[UICollectionView class]]) { - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [super endRefreshing]; - }); - } else { - [super endRefreshing]; - } + dispatch_async(dispatch_get_main_queue(), ^{ + self.state = MJRefreshStateIdle; + }); } - (NSDate *)lastUpdatedTime diff --git a/MJRefreshExample/Classes/Second/MJCollectionViewController.m b/MJRefreshExample/Classes/Second/MJCollectionViewController.m index 6b78fc3d..ade5b318 100644 --- a/MJRefreshExample/Classes/Second/MJCollectionViewController.m +++ b/MJRefreshExample/Classes/Second/MJCollectionViewController.m @@ -48,7 +48,7 @@ - (void)example21 [self.collectionView.mj_header beginRefreshing]; // 上拉刷新 - self.collectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{ + self.collectionView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{ // 增加5条假数据 for (int i = 0; i<5; i++) { [weakSelf.colors addObject:MJRandomColor];