From bf50d1089bceea87ddee2cd9a81b0df1c47f3e58 Mon Sep 17 00:00:00 2001 From: Amber Conville Date: Tue, 6 Nov 2012 13:48:05 -0500 Subject: [PATCH] Making pull distance based on the size of the table it is within. --- .../Classes/View/EGORefreshTableHeaderView.m | 44 +++++++++++++------ 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/EGOTableViewPullRefresh/Classes/View/EGORefreshTableHeaderView.m b/EGOTableViewPullRefresh/Classes/View/EGORefreshTableHeaderView.m index 56b345b..c45f7b2 100755 --- a/EGOTableViewPullRefresh/Classes/View/EGORefreshTableHeaderView.m +++ b/EGOTableViewPullRefresh/Classes/View/EGORefreshTableHeaderView.m @@ -45,8 +45,8 @@ - (id)initWithFrame:(CGRect)frame arrowImageName:(NSString *)arrow textColor:(UI self.autoresizingMask = UIViewAutoresizingFlexibleWidth; self.backgroundColor = [UIColor colorWithRed:226.0/255.0 green:231.0/255.0 blue:237.0/255.0 alpha:1.0]; - - UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, frame.size.height - 30.0f, self.frame.size.width, 20.0f)]; + + UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, frame.size.height - 30.0f, self.frame.size.width, 20.0f)]; label.autoresizingMask = UIViewAutoresizingFlexibleWidth; label.font = [UIFont systemFontOfSize:12.0f]; label.textColor = textColor; @@ -71,7 +71,7 @@ - (id)initWithFrame:(CGRect)frame arrowImageName:(NSString *)arrow textColor:(UI [label release]; CALayer *layer = [CALayer layer]; - layer.frame = CGRectMake(25.0f, frame.size.height - 65.0f, 30.0f, 55.0f); + layer.frame = [self makeArrowFrameForContainer:frame]; layer.contentsGravity = kCAGravityResizeAspect; layer.contents = (id)[UIImage imageNamed:arrow].CGImage; @@ -99,8 +99,24 @@ - (id)initWithFrame:(CGRect)frame arrowImageName:(NSString *)arrow textColor:(UI } +- (CGRect)makeArrowFrameForContainer:(CGRect)frame { + CGFloat arrowY = frame.size.height - 65.0f; + float arrowHeight = 55.0f; + if(frame.size.height < 65){ + arrowY = 10; + arrowHeight = frame.size.height - 20; + } + CGRect arrowFrame = CGRectMake(25.0f, arrowY, 30.0f, arrowHeight); + return arrowFrame; +} + +- (float)getPullDistance { + return self.superview.frame.size.height/4; + // return 65.0f; +} + - (id)initWithFrame:(CGRect)frame { - return [self initWithFrame:frame arrowImageName:@"blueArrow.png" textColor:TEXT_COLOR]; + return [self initWithFrame:frame arrowImageName:@"blueArrow.png" textColor:TEXT_COLOR]; } #pragma mark - @@ -116,7 +132,7 @@ - (void)refreshLastUpdatedDate { NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setDateStyle:NSDateFormatterShortStyle]; [dateFormatter setTimeStyle:NSDateFormatterShortStyle]; - + _lastUpdatedLabel.text = [NSString stringWithFormat:@"Last Updated: %@", [dateFormatter stringFromDate:date]]; [[NSUserDefaults standardUserDefaults] setObject:_lastUpdatedLabel.text forKey:@"EGORefreshTableView_LastRefresh"]; [[NSUserDefaults standardUserDefaults] synchronize]; @@ -126,7 +142,7 @@ - (void)refreshLastUpdatedDate { _lastUpdatedLabel.text = nil; } - + } - (void)setState:(EGOPullRefreshState)aState{ @@ -153,7 +169,7 @@ - (void)setState:(EGOPullRefreshState)aState{ _statusLabel.text = NSLocalizedString(@"Pull down to refresh...", @"Pull down to refresh status"); [_activityView stopAnimating]; [CATransaction begin]; - [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions]; + [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions]; _arrowImage.hidden = NO; _arrowImage.transform = CATransform3DIdentity; [CATransaction commit]; @@ -166,7 +182,7 @@ - (void)setState:(EGOPullRefreshState)aState{ _statusLabel.text = NSLocalizedString(@"Loading...", @"Loading Status"); [_activityView startAnimating]; [CATransaction begin]; - [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions]; + [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions]; _arrowImage.hidden = YES; [CATransaction commit]; @@ -182,7 +198,7 @@ - (void)setState:(EGOPullRefreshState)aState{ #pragma mark - #pragma mark ScrollView Methods -- (void)egoRefreshScrollViewDidScroll:(UIScrollView *)scrollView { +- (void)egoRefreshScrollViewDidScroll:(UIScrollView *)scrollView { if (_state == EGOOPullRefreshLoading) { @@ -197,9 +213,9 @@ - (void)egoRefreshScrollViewDidScroll:(UIScrollView *)scrollView { _loading = [_delegate egoRefreshTableHeaderDataSourceIsLoading:self]; } - if (_state == EGOOPullRefreshPulling && scrollView.contentOffset.y > -65.0f && scrollView.contentOffset.y < 0.0f && !_loading) { + if (_state == EGOOPullRefreshPulling && scrollView.contentOffset.y > ([self getPullDistance] * -1) && scrollView.contentOffset.y < 0.0f && !_loading) { [self setState:EGOOPullRefreshNormal]; - } else if (_state == EGOOPullRefreshNormal && scrollView.contentOffset.y < -65.0f && !_loading) { + } else if (_state == EGOOPullRefreshNormal && scrollView.contentOffset.y < ([self getPullDistance] * -1) && !_loading) { [self setState:EGOOPullRefreshPulling]; } @@ -218,7 +234,7 @@ - (void)egoRefreshScrollViewDidEndDragging:(UIScrollView *)scrollView { _loading = [_delegate egoRefreshTableHeaderDataSourceIsLoading:self]; } - if (scrollView.contentOffset.y <= - 65.0f && !_loading) { + if (scrollView.contentOffset.y <= ([self getPullDistance] * -1) && !_loading) { if ([_delegate respondsToSelector:@selector(egoRefreshTableHeaderDidTriggerRefresh:)]) { [_delegate egoRefreshTableHeaderDidTriggerRefresh:self]; @@ -234,7 +250,7 @@ - (void)egoRefreshScrollViewDidEndDragging:(UIScrollView *)scrollView { } -- (void)egoRefreshScrollViewDataSourceDidFinishedLoading:(UIScrollView *)scrollView { +- (void)egoRefreshScrollViewDataSourceDidFinishedLoading:(UIScrollView *)scrollView { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:.3]; @@ -242,7 +258,7 @@ - (void)egoRefreshScrollViewDataSourceDidFinishedLoading:(UIScrollView *)scrollV [UIView commitAnimations]; [self setState:EGOOPullRefreshNormal]; - + }