From 42d6572637dcb0f8342cb7035bc7478aad24696c Mon Sep 17 00:00:00 2001 From: Nikolaj Schumacher Date: Sun, 5 Jun 2011 15:55:49 +0200 Subject: [PATCH 1/4] Added internationalization for "Last Updated" label. --- .../Classes/View/EGORefreshTableHeaderView.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/EGOTableViewPullRefresh/Classes/View/EGORefreshTableHeaderView.m b/EGOTableViewPullRefresh/Classes/View/EGORefreshTableHeaderView.m index 56b345b..5db3f5d 100755 --- a/EGOTableViewPullRefresh/Classes/View/EGORefreshTableHeaderView.m +++ b/EGOTableViewPullRefresh/Classes/View/EGORefreshTableHeaderView.m @@ -110,6 +110,8 @@ - (void)refreshLastUpdatedDate { if ([_delegate respondsToSelector:@selector(egoRefreshTableHeaderDataSourceLastUpdated:)]) { + NSString *label = NSLocalizedString(@"Last Updated", @"Last Updated label"); + NSDate *date = [_delegate egoRefreshTableHeaderDataSourceLastUpdated:self]; [NSDateFormatter setDefaultFormatterBehavior:NSDateFormatterBehaviorDefault]; @@ -117,7 +119,7 @@ - (void)refreshLastUpdatedDate { [dateFormatter setDateStyle:NSDateFormatterShortStyle]; [dateFormatter setTimeStyle:NSDateFormatterShortStyle]; - _lastUpdatedLabel.text = [NSString stringWithFormat:@"Last Updated: %@", [dateFormatter stringFromDate:date]]; + _lastUpdatedLabel.text = [NSString stringWithFormat:@"%@: %@", label, [dateFormatter stringFromDate:date]]; [[NSUserDefaults standardUserDefaults] setObject:_lastUpdatedLabel.text forKey:@"EGORefreshTableView_LastRefresh"]; [[NSUserDefaults standardUserDefaults] synchronize]; From f0a3c3662b944f04c73c01d157d28448f1dc446d Mon Sep 17 00:00:00 2001 From: Nikolaj Schumacher Date: Tue, 10 Apr 2012 23:31:02 +0200 Subject: [PATCH 2/4] Show activity indicator when pulling while source is loading. When "egoRefreshTableHeaderDataSourceIsLoading:" returns YES, pulling now displays the activity indicator instead of "Pull down to refresh...". --- .../Classes/View/EGORefreshTableHeaderView.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/EGOTableViewPullRefresh/Classes/View/EGORefreshTableHeaderView.m b/EGOTableViewPullRefresh/Classes/View/EGORefreshTableHeaderView.m index 5db3f5d..f9952a1 100755 --- a/EGOTableViewPullRefresh/Classes/View/EGORefreshTableHeaderView.m +++ b/EGOTableViewPullRefresh/Classes/View/EGORefreshTableHeaderView.m @@ -199,9 +199,11 @@ - (void)egoRefreshScrollViewDidScroll:(UIScrollView *)scrollView { _loading = [_delegate egoRefreshTableHeaderDataSourceIsLoading:self]; } - if (_state == EGOOPullRefreshPulling && scrollView.contentOffset.y > -65.0f && scrollView.contentOffset.y < 0.0f && !_loading) { + if (_loading) { + [self setState:EGOOPullRefreshLoading]; + } else if (_state == EGOOPullRefreshPulling && scrollView.contentOffset.y > -65.0f && scrollView.contentOffset.y < 0.0f) { [self setState:EGOOPullRefreshNormal]; - } else if (_state == EGOOPullRefreshNormal && scrollView.contentOffset.y < -65.0f && !_loading) { + } else if (_state == EGOOPullRefreshNormal && scrollView.contentOffset.y < -65.0f) { [self setState:EGOOPullRefreshPulling]; } From 7b850f290dfda4361d289107b9661c307ded81d1 Mon Sep 17 00:00:00 2001 From: Nikolaj Schumacher Date: Thu, 5 Apr 2012 17:30:25 +0200 Subject: [PATCH 3/4] Don't override content insets set elsewhere --- .../Classes/View/EGORefreshTableHeaderView.m | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/EGOTableViewPullRefresh/Classes/View/EGORefreshTableHeaderView.m b/EGOTableViewPullRefresh/Classes/View/EGORefreshTableHeaderView.m index f9952a1..74c52a8 100755 --- a/EGOTableViewPullRefresh/Classes/View/EGORefreshTableHeaderView.m +++ b/EGOTableViewPullRefresh/Classes/View/EGORefreshTableHeaderView.m @@ -184,13 +184,21 @@ - (void)setState:(EGOPullRefreshState)aState{ #pragma mark - #pragma mark ScrollView Methods +- (void)setContentOffset:(float)offset + forScrollView:(UIScrollView *)scrollView { + + UIEdgeInsets inset = scrollView.contentInset; + inset.top = offset; + scrollView.contentInset = inset; +} + - (void)egoRefreshScrollViewDidScroll:(UIScrollView *)scrollView { if (_state == EGOOPullRefreshLoading) { CGFloat offset = MAX(scrollView.contentOffset.y * -1, 0); offset = MIN(offset, 60); - scrollView.contentInset = UIEdgeInsetsMake(offset, 0.0f, 0.0f, 0.0f); + [self setContentOffset: offset forScrollView: scrollView]; } else if (scrollView.isDragging) { @@ -207,10 +215,7 @@ - (void)egoRefreshScrollViewDidScroll:(UIScrollView *)scrollView { [self setState:EGOOPullRefreshPulling]; } - if (scrollView.contentInset.top != 0) { - scrollView.contentInset = UIEdgeInsetsZero; - } - + [self setContentOffset: 0 forScrollView: scrollView]; } } @@ -231,7 +236,7 @@ - (void)egoRefreshScrollViewDidEndDragging:(UIScrollView *)scrollView { [self setState:EGOOPullRefreshLoading]; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.2]; - scrollView.contentInset = UIEdgeInsetsMake(60.0f, 0.0f, 0.0f, 0.0f); + [self setContentOffset: 60.0f forScrollView: scrollView]; [UIView commitAnimations]; } @@ -242,7 +247,7 @@ - (void)egoRefreshScrollViewDataSourceDidFinishedLoading:(UIScrollView *)scrollV [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:.3]; - [scrollView setContentInset:UIEdgeInsetsMake(0.0f, 0.0f, 0.0f, 0.0f)]; + [self setContentOffset: 0.0f forScrollView: scrollView]; [UIView commitAnimations]; [self setState:EGOOPullRefreshNormal]; From c840c975b83e07dcca0956973737929587c1e73a Mon Sep 17 00:00:00 2001 From: Nikolaj Schumacher Date: Tue, 11 Sep 2012 22:34:07 +0200 Subject: [PATCH 4/4] Support regular state contentInsets other than 0. --- .../Classes/View/EGORefreshTableHeaderView.h | 1 + .../Classes/View/EGORefreshTableHeaderView.m | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/EGOTableViewPullRefresh/Classes/View/EGORefreshTableHeaderView.h b/EGOTableViewPullRefresh/Classes/View/EGORefreshTableHeaderView.h index 0ec72f0..ee4e932 100755 --- a/EGOTableViewPullRefresh/Classes/View/EGORefreshTableHeaderView.h +++ b/EGOTableViewPullRefresh/Classes/View/EGORefreshTableHeaderView.h @@ -48,6 +48,7 @@ typedef enum{ } @property(nonatomic,assign) id delegate; +@property (nonatomic, assign) float defaultOffset; - (id)initWithFrame:(CGRect)frame arrowImageName:(NSString *)arrow textColor:(UIColor *)textColor; diff --git a/EGOTableViewPullRefresh/Classes/View/EGORefreshTableHeaderView.m b/EGOTableViewPullRefresh/Classes/View/EGORefreshTableHeaderView.m index 74c52a8..0c3b48c 100755 --- a/EGOTableViewPullRefresh/Classes/View/EGORefreshTableHeaderView.m +++ b/EGOTableViewPullRefresh/Classes/View/EGORefreshTableHeaderView.m @@ -38,7 +38,7 @@ - (void)setState:(EGOPullRefreshState)aState; @implementation EGORefreshTableHeaderView @synthesize delegate=_delegate; - +@synthesize defaultOffset=_defaultOffset; - (id)initWithFrame:(CGRect)frame arrowImageName:(NSString *)arrow textColor:(UIColor *)textColor { if((self = [super initWithFrame:frame])) { @@ -215,7 +215,7 @@ - (void)egoRefreshScrollViewDidScroll:(UIScrollView *)scrollView { [self setState:EGOOPullRefreshPulling]; } - [self setContentOffset: 0 forScrollView: scrollView]; + [self setContentOffset:self.defaultOffset forScrollView: scrollView]; } } @@ -247,7 +247,7 @@ - (void)egoRefreshScrollViewDataSourceDidFinishedLoading:(UIScrollView *)scrollV [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:.3]; - [self setContentOffset: 0.0f forScrollView: scrollView]; + [self setContentOffset:self.defaultOffset forScrollView: scrollView]; [UIView commitAnimations]; [self setState:EGOOPullRefreshNormal];