Permalink
Browse files

Reverting some things

  • Loading branch information...
1 parent 1955e58 commit afdbdd518313dcf7c1e3486fce624a8f8312a25b @Sephiroth87 committed Sep 19, 2012
Showing with 44 additions and 21 deletions.
  1. +19 −0 ODRefreshControl.podspec
  2. +2 −2 ODRefreshControl/ODRefreshControl.h
  3. +23 −19 ODRefreshControl/ODRefreshControl.m
View
19 ODRefreshControl.podspec
@@ -0,0 +1,19 @@
+Pod::Spec.new do |s|
+ s.name = 'ODRefreshControl'
+ s.version = '1.0.0'
+ s.license = 'MIT'
+ s.summary = "A pull down to refresh control like the one in Apple's iOS6 Mail App."
+ s.homepage = 'https://github.com/Sephiroth87/ODRefreshControl'
+ s.author = { 'Fabio Ritrovato' => 'fabio@orangeinaday.com' }
+ s.source = { :git => 'https://github.com/Sephiroth87/ODRefreshControl.git', :tag => '1.0.0' }
+
+ s.description = 'ODRefreshControl is a "pull down to refresh" control for UIScrollView,' \
+ 'like the one Apple introduced in iOS6, but available to anyone from iOS4 and up.'
+ s.platform = :ios
+
+ s.source_files = 'ODRefreshControl/ODRefreshControl*.{h,m}'
+ s.clean_path = 'Demo'
+ s.framework = 'QuartzCore'
+
+ s.requires_arc = true
+end
View
4 ODRefreshControl/ODRefreshControl.h
@@ -15,7 +15,7 @@
CAShapeLayer *_shapeLayer;
CAShapeLayer *_arrowLayer;
CAShapeLayer *_highlightLayer;
- id _activity;
+ UIView *_activity;
BOOL _refreshing;
BOOL _canRefresh;
BOOL _ignoreInset;
@@ -31,7 +31,7 @@
- (id)initInScrollView:(UIScrollView *)scrollView;
// use custom activity indicator
-- (id)initInScrollView:(UIScrollView *)scrollView withActivityIndicator:(id)activity;
+- (id)initInScrollView:(UIScrollView *)scrollView activityIndicatorView:(UIView *)activity;
// Tells the control that a refresh operation was started programmatically
- (void)beginRefreshing;
View
42 ODRefreshControl/ODRefreshControl.m
@@ -35,6 +35,7 @@ @interface ODRefreshControl ()
@end
@implementation ODRefreshControl
+
@synthesize refreshing = _refreshing;
@synthesize tintColor = _tintColor;
@@ -47,10 +48,10 @@ static inline CGFloat lerp(CGFloat a, CGFloat b, CGFloat p)
}
- (id)initInScrollView:(UIScrollView *)scrollView {
- return [self initInScrollView:scrollView withActivityIndicator:nil];
+ return [self initInScrollView:scrollView activityIndicatorView:nil];
}
-- (id)initInScrollView:(UIScrollView *)scrollView withActivityIndicator:(id)activity
+- (id)initInScrollView:(UIScrollView *)scrollView activityIndicatorView:(UIView *)activity
{
self = [super initWithFrame:CGRectMake(0, -(kTotalViewHeight + scrollView.contentInset.top), scrollView.frame.size.width, kTotalViewHeight)];
@@ -64,9 +65,12 @@ - (id)initInScrollView:(UIScrollView *)scrollView withActivityIndicator:(id)acti
[scrollView addObserver:self forKeyPath:@"contentInset" options:NSKeyValueObservingOptionNew context:nil];
_activity = activity ? activity : [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
- [_activity setCenter:CGPointMake(floor(self.frame.size.width / 2), floor(self.frame.size.height / 2))];
- [_activity setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin];
- [_activity setAlpha:0];
+ _activity.center = CGPointMake(floor(self.frame.size.width / 2), floor(self.frame.size.height / 2));
+ _activity.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
+ _activity.alpha = 0;
+ if ([_activity respondsToSelector:@selector(startAnimating)]) {
+ [(UIActivityIndicatorView *)_activity startAnimating];
+ }
[self addSubview:_activity];
_refreshing = NO;
@@ -131,15 +135,16 @@ - (void)setTintColor:(UIColor *)tintColor
- (void)setActivityIndicatorViewStyle:(UIActivityIndicatorViewStyle)activityIndicatorViewStyle
{
- if ([_activity isMemberOfClass:[UIActivityIndicatorView class]])
- [_activity setActivityIndicatorViewStyle:activityIndicatorViewStyle];
+ if ([_activity isKindOfClass:[UIActivityIndicatorView class]]) {
+ [(UIActivityIndicatorView *)_activity setActivityIndicatorViewStyle:activityIndicatorViewStyle];
+ }
}
- (UIActivityIndicatorViewStyle)activityIndicatorViewStyle
{
- if ([_activity isMemberOfClass:[UIActivityIndicatorView class]])
- return [_activity activityIndicatorViewStyle];
-
+ if ([_activity isKindOfClass:[UIActivityIndicatorView class]]) {
+ return [(UIActivityIndicatorView *)_activity activityIndicatorViewStyle];
+ }
return 0;
}
@@ -168,7 +173,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
_shapeLayer.position = CGPointMake(0, kMaxDistance + offset + kOpenedViewHeight);
[CATransaction commit];
- [_activity setCenter:CGPointMake(floor(self.frame.size.width / 2), MIN(offset + self.frame.size.height + floor(kOpenedViewHeight / 2), self.frame.size.height - kOpenedViewHeight/ 2))];
+ _activity.center = CGPointMake(floor(self.frame.size.width / 2), MIN(offset + self.frame.size.height + floor(kOpenedViewHeight / 2), self.frame.size.height - kOpenedViewHeight/ 2));
_ignoreInset = YES;
_ignoreOffset = YES;
@@ -342,16 +347,15 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
- [_activity layer].transform = CATransform3DMakeScale(0.1, 0.1, 1);
+ _activity.layer.transform = CATransform3DMakeScale(0.1, 0.1, 1);
[CATransaction commit];
[UIView animateWithDuration:0.2 delay:0.15 options:UIViewAnimationOptionCurveLinear animations:^{
- [_activity setAlpha:1];
- [_activity layer].transform = CATransform3DMakeScale(1, 1, 1);
+ _activity.alpha = 1;
+ _activity.layer.transform = CATransform3DMakeScale(1, 1, 1);
} completion:nil];
self.refreshing = YES;
_canRefresh = NO;
- [_activity startAnimating];
[self sendActionsForControlEvents:UIControlEventValueChanged];
}
@@ -370,8 +374,8 @@ - (void)beginRefreshing
[_arrowLayer addAnimation:alphaAnimation forKey:nil];
[_highlightLayer addAnimation:alphaAnimation forKey:nil];
- [_activity setAlpha:1];
- [_activity layer].transform = CATransform3DMakeScale(1, 1, 1);
+ _activity.alpha = 1;
+ _activity.layer.transform = CATransform3DMakeScale(1, 1, 1);
CGPoint offset = self.scrollView.contentOffset;
_ignoreInset = YES;
@@ -397,8 +401,8 @@ - (void)endRefreshing
_ignoreInset = YES;
[blockScrollView setContentInset:self.originalContentInset];
_ignoreInset = NO;
- [_activity setAlpha:0];
- [_activity layer].transform = CATransform3DMakeScale(0.1, 0.1, 1);
+ _activity.alpha = 0;
+ _activity.layer.transform = CATransform3DMakeScale(0.1, 0.1, 1);
} completion:^(BOOL finished) {
[_shapeLayer removeAllAnimations];
_shapeLayer.path = nil;

0 comments on commit afdbdd5

Please sign in to comment.