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 56b345b..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])) { @@ -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]; @@ -182,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) { @@ -197,16 +207,15 @@ - (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]; } - if (scrollView.contentInset.top != 0) { - scrollView.contentInset = UIEdgeInsetsZero; - } - + [self setContentOffset:self.defaultOffset forScrollView: scrollView]; } } @@ -227,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]; } @@ -238,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:self.defaultOffset forScrollView: scrollView]; [UIView commitAnimations]; [self setState:EGOOPullRefreshNormal];