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
4 changes: 4 additions & 0 deletions Class/CBStoreHouseRefreshControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

@interface CBStoreHouseRefreshControl : UIView



+ (CBStoreHouseRefreshControl*)attachToScrollView:(UIScrollView *)scrollView
target:(id)target
refreshAction:(SEL)refreshAction
Expand All @@ -33,4 +35,6 @@

- (void)finishingLoading;

- (int)refreshcontrolstate;

@end
84 changes: 69 additions & 15 deletions Class/CBStoreHouseRefreshControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,37 @@
#import "BarItem.h"

static const CGFloat kloadingIndividualAnimationTiming = 0.8;
static const CGFloat kbarDarkAlpha = 0.4;
static const CGFloat kloadingTimingOffset = 0.1;
static const CGFloat kdisappearDuration = 1.2;
static const CGFloat kbarDarkAlpha = 0.2;
static const CGFloat kloadingTimingOffset = 0.021;
static const CGFloat kdisappearDuration = 0.5;
static const CGFloat krelativeHeightFactor = 2.f/5.f;

typedef enum {
CBStoreHouseRefreshControlStateIdle = 0,
CBStoreHouseRefreshControlStateRefreshing = 1,
CBStoreHouseRefreshControlStateDisappearing = 2
CBStoreHouseRefreshControlStateDisappearing = 2,

} CBStoreHouseRefreshControlState;


NSString *const startPointKey = @"startPoints";
NSString *const endPointKey = @"endPoints";
NSString *const xKey = @"x";
NSString *const yKey = @"y";

@interface CBStoreHouseRefreshControl () <UIScrollViewDelegate>

@property (nonatomic) CBStoreHouseRefreshControlState state;

@property (nonatomic) CBStoreHouseRefreshControlState* state;
@property (nonatomic, weak) UIScrollView *scrollView;
@property (nonatomic, strong) NSArray *barItems;
@property (nonatomic, strong) CADisplayLink *displayLink;
@property (nonatomic, assign) id target;
@property (nonatomic) SEL action;

@property (nonatomic) CGFloat dropHeight;
@property (nonatomic) CGFloat originalTopContentInset;
@property (nonatomic) CGFloat disappearProgress;
@property (nonatomic) CGFloat internalAnimationFactor;
@property (nonatomic) CGFloat originalTopContentInset;
@property (nonatomic) int horizontalRandomness;
@property (nonatomic) BOOL reverseLoadingAnimation;

Expand Down Expand Up @@ -97,10 +99,10 @@ + (CBStoreHouseRefreshControl*)attachToScrollView:(UIScrollView *)scrollView
CGPoint startPoint = CGPointFromString(startPoints[i]);
CGPoint endPoint = CGPointFromString(endPoints[i]);

if (startPoint.x > width) width = startPoint.x;
if (endPoint.x > width) width = endPoint.x;
if (startPoint.y > height) height = startPoint.y;
if (endPoint.y > height) height = endPoint.y;
if (startPoint.x + lineWidth > width) width = startPoint.x + lineWidth;
if (endPoint.x + lineWidth > width) width = endPoint.x + lineWidth;
if (startPoint.y + lineWidth > height) height = startPoint.y + lineWidth;
if (endPoint.y + lineWidth > height) height = endPoint.y + lineWidth;
}
refreshControl.frame = CGRectMake(0, 0, width, height);

Expand All @@ -111,6 +113,10 @@ + (CBStoreHouseRefreshControl*)attachToScrollView:(UIScrollView *)scrollView
CGPoint startPoint = CGPointFromString(startPoints[i]);
CGPoint endPoint = CGPointFromString(endPoints[i]);

// shift it base on line width
startPoint = CGPointMake(startPoint.x + lineWidth/2, startPoint.y + lineWidth/2);
endPoint = CGPointMake(endPoint.x + lineWidth/2, endPoint.y + lineWidth/2);

BarItem *barItem = [[BarItem alloc] initWithFrame:refreshControl.frame startPoint:startPoint endPoint:endPoint color:color lineWidth:lineWidth];
barItem.tag = i;
barItem.backgroundColor=[UIColor clearColor];
Expand All @@ -123,7 +129,12 @@ + (CBStoreHouseRefreshControl*)attachToScrollView:(UIScrollView *)scrollView

refreshControl.barItems = [NSArray arrayWithArray:mutableBarItems];
refreshControl.frame = CGRectMake(0, 0, width, height);
refreshControl.center = CGPointMake([UIScreen mainScreen].bounds.size.width/2, 0);
//refreshControl.center = CGPointMake([UIScreen mainScreen].bounds.size.width/2, 0);



refreshControl.center = CGPointMake(scrollView.frame.size.width/2, 0);

for (BarItem *barItem in refreshControl.barItems) {
[barItem setupWithFrame:refreshControl.frame];
}
Expand All @@ -136,14 +147,47 @@ + (CBStoreHouseRefreshControl*)attachToScrollView:(UIScrollView *)scrollView

- (void)scrollViewDidScroll
{
if (self.originalTopContentInset == 0) self.originalTopContentInset = self.scrollView.contentInset.top;
self.center = CGPointMake([UIScreen mainScreen].bounds.size.width/2, self.realContentOffsetY*krelativeHeightFactor);
if (self.state == CBStoreHouseRefreshControlStateIdle)
// not ok BUGFIX beim start if (self.originalTopContentInset == 0) self.originalTopContentInset = self.scrollView.contentInset.top;
self.center = CGPointMake(_scrollView.bounds.size.width/2, self.realContentOffsetY*krelativeHeightFactor);
if (self.state == CBStoreHouseRefreshControlStateIdle){
//BUGFIX beim drehen
//TODO checks auf ipad!
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)){
if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad )
{
self.originalTopContentInset = 64;

}else{
self.originalTopContentInset = 44;
}

}else{
self.originalTopContentInset = 64;

}
[self updateBarItemsWithProgress:self.animationProgress];
}

/*
BUGFIX wenn refresh läuft..

CGFloat offset = MAX(self.scrollView.contentOffset.y * -1, 0.0f);
offset = MIN(offset, self.originalTopContentInset + self.dropHeight);
offset = MAX(offset, self.originalTopContentInset);
UIEdgeInsets contentInset = self.scrollView.contentInset;
self.scrollView.contentInset = UIEdgeInsetsMake(offset, contentInset.left, contentInset.bottom, contentInset.right);

//BUGFIX
*/

}



- (void)scrollViewDidEndDragging
{


if (self.state == CBStoreHouseRefreshControlStateIdle && self.realContentOffsetY < -self.dropHeight) {

if (self.animationProgress == 1) self.state = CBStoreHouseRefreshControlStateRefreshing;
Expand All @@ -166,6 +210,10 @@ - (void)scrollViewDidEndDragging
[self.target performSelector:self.action withObject:self];

#pragma clang diagnostic pop
UIImpactFeedbackGenerator *myGen = [[UIImpactFeedbackGenerator alloc] init];
[myGen initWithStyle:(UIImpactFeedbackStyleMedium)];
[myGen impactOccurred];
myGen = NULL;

[self startLoadingAnimation];
}
Expand Down Expand Up @@ -271,8 +319,10 @@ - (void)finishingLoading
[UIView animateWithDuration:kdisappearDuration animations:^(void) {
self.scrollView.contentInset = newInsets;
} completion:^(BOOL finished) {

self.state = CBStoreHouseRefreshControlStateIdle;
[self.displayLink invalidate];
self.displayLink = nil;
self.disappearProgress = 1;
}];

Expand All @@ -286,4 +336,8 @@ - (void)finishingLoading
self.disappearProgress = 1;
}

- (int)refreshcontrolstate{
return self.state;
}

@end