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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ build/*
xcuserdata
profile
*.moved-aside
.DS_Store
2 changes: 1 addition & 1 deletion Classes/DemoTableViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

#import <UIKit/UIKit.h>
#import "PullRefreshTableViewController.h"
#import <PullToRefresh/PullRefreshTableViewController.h>

@interface DemoTableViewController : PullRefreshTableViewController {
NSMutableArray *items;
Expand Down
26 changes: 22 additions & 4 deletions Classes/PullRefreshTableViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,28 @@
NSString *textLoading;
}

@property (nonatomic, retain) UIView *refreshHeaderView;
@property (nonatomic, retain) UILabel *refreshLabel;
@property (nonatomic, retain) UIImageView *refreshArrow;
@property (nonatomic, retain) UIActivityIndicatorView *refreshSpinner;
#ifndef PTR_STRONG
#if __has_feature(objc_arc)
#define PTR_STRONG strong
#else
#define PTR_STRONG retain
#endif
#endif

#ifndef PTR_WEAK
#if __has_feature(objc_arc_weak)
#define PTR_WEAK weak
#elif __has_feature(objc_arc)
#define PTR_WEAK unsafe_unretained
#else
#define PTR_WEAK assign
#endif
#endif

@property (nonatomic, PTR_STRONG) UIView *refreshHeaderView;
@property (nonatomic, PTR_STRONG) UILabel *refreshLabel;
@property (nonatomic, PTR_STRONG) UIImageView *refreshArrow;
@property (nonatomic, PTR_STRONG) UIActivityIndicatorView *refreshSpinner;
@property (nonatomic, copy) NSString *textPull;
@property (nonatomic, copy) NSString *textRelease;
@property (nonatomic, copy) NSString *textLoading;
Expand Down
27 changes: 15 additions & 12 deletions Classes/PullRefreshTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
// OTHER DEALINGS IN THE SOFTWARE.
//

#import <QuartzCore/QuartzCore.h>
#import "PullRefreshTableViewController.h"

#define REFRESH_HEADER_HEIGHT 52.0f
Expand Down Expand Up @@ -66,22 +65,24 @@ - (void)viewDidLoad {
[self addPullToRefreshHeader];
}

- (void)setupStrings{
- (void)setupStrings {
textPull = [[NSString alloc] initWithString:@"Pull down to refresh..."];
textRelease = [[NSString alloc] initWithString:@"Release to refresh..."];
textLoading = [[NSString alloc] initWithString:@"Loading..."];
}

- (void)addPullToRefreshHeader {
refreshHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0 - REFRESH_HEADER_HEIGHT, 320, REFRESH_HEADER_HEIGHT)];
CGFloat width = [[UIScreen mainScreen] bounds].size.width;
refreshHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0 - REFRESH_HEADER_HEIGHT, width, REFRESH_HEADER_HEIGHT)];
refreshHeaderView.backgroundColor = [UIColor clearColor];

refreshLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, REFRESH_HEADER_HEIGHT)];
refreshLabel.backgroundColor = [UIColor clearColor];
refreshLabel.font = [UIFont boldSystemFontOfSize:12.0];
refreshLabel.textAlignment = UITextAlignmentCenter;
refreshLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, width, REFRESH_HEADER_HEIGHT)];
refreshLabel.backgroundColor = [UIColor clearColor];
refreshLabel.font = [UIFont boldSystemFontOfSize:12.0];
refreshLabel.textAlignment = UITextAlignmentCenter;
refreshLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;

refreshArrow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow.png"]];
refreshArrow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"PullToRefresh.framework/arrow.png"]];
refreshArrow.frame = CGRectMake(floorf((REFRESH_HEADER_HEIGHT - 27) / 2),
(floorf(REFRESH_HEADER_HEIGHT - 44) / 2),
27, 44);
Expand Down Expand Up @@ -114,11 +115,11 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView.contentOffset.y < -REFRESH_HEADER_HEIGHT) {
// User is scrolling above the header
refreshLabel.text = self.textRelease;
[refreshArrow layer].transform = CATransform3DMakeRotation(M_PI, 0, 0, 1);
} else {
refreshArrow.transform = CGAffineTransformMakeRotation(M_PI);
} else {
// User is scrolling somewhere within the header
refreshLabel.text = self.textPull;
[refreshArrow layer].transform = CATransform3DMakeRotation(M_PI * 2, 0, 0, 1);
refreshArrow.transform = CGAffineTransformMakeRotation(0);
}
}];
}
Expand Down Expand Up @@ -154,7 +155,7 @@ - (void)stopLoading {
// Hide the header
[UIView animateWithDuration:0.3 animations:^{
self.tableView.contentInset = UIEdgeInsetsZero;
[refreshArrow layer].transform = CATransform3DMakeRotation(M_PI * 2, 0, 0, 1);
refreshArrow.transform = CGAffineTransformMakeRotation(0);
}
completion:^(BOOL finished) {
[self performSelector:@selector(stopLoadingComplete)];
Expand All @@ -174,6 +175,7 @@ - (void)refresh {
[self performSelector:@selector(stopLoading) withObject:nil afterDelay:2.0];
}

#if !__has_feature(objc_arc)
- (void)dealloc {
[refreshHeaderView release];
[refreshLabel release];
Expand All @@ -184,5 +186,6 @@ - (void)dealloc {
[textLoading release];
[super dealloc];
}
#endif

@end
Loading