Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Make the pull-to-refresh distance change based on superview #54

Open
wants to merge 1 commit into from

1 participant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 30 additions and 14 deletions.
  1. +30 −14 EGOTableViewPullRefresh/Classes/View/EGORefreshTableHeaderView.m
View
44 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];
-
+
}
Something went wrong with that request. Please try again.