Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ typedef enum{
}

@property(nonatomic,assign) id <EGORefreshTableHeaderDelegate> delegate;
@property (nonatomic, assign) float defaultOffset;

- (id)initWithFrame:(CGRect)frame arrowImageName:(NSString *)arrow textColor:(UIColor *)textColor;

Expand Down
31 changes: 20 additions & 11 deletions EGOTableViewPullRefresh/Classes/View/EGORefreshTableHeaderView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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])) {
Expand Down Expand Up @@ -110,14 +110,16 @@ - (void)refreshLastUpdatedDate {

if ([_delegate respondsToSelector:@selector(egoRefreshTableHeaderDataSourceLastUpdated:)]) {

NSString *label = NSLocalizedString(@"Last Updated", @"Last Updated label");

NSDate *date = [_delegate egoRefreshTableHeaderDataSourceLastUpdated:self];

[NSDateFormatter setDefaultFormatterBehavior:NSDateFormatterBehaviorDefault];
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[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];

Expand Down Expand Up @@ -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) {

Expand All @@ -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];
}

}
Expand All @@ -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];

}
Expand All @@ -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];
Expand Down