Skip to content

Commit

Permalink
Add pre build script to copy modified ITPullToRefreshScrollView files…
Browse files Browse the repository at this point in the history
… to pods
  • Loading branch information
yeahdongcn committed May 13, 2014
1 parent d73d03c commit 6531758
Show file tree
Hide file tree
Showing 7 changed files with 777 additions and 0 deletions.
14 changes: 14 additions & 0 deletions CocoaControls/CocoaControls.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
isa = PBXNativeTarget;
buildConfigurationList = D0108A771913CCD500912C70 /* Build configuration list for PBXNativeTarget "CocoaControls" */;
buildPhases = (
D0C0DBA71921BC2900D46E04 /* ShellScript */,
E3C44B8F592D4DBA8D8DAF66 /* Check Pods Manifest.lock */,
D0108A421913CCD500912C70 /* Sources */,
D0108A431913CCD500912C70 /* Frameworks */,
Expand Down Expand Up @@ -269,6 +270,19 @@
shellPath = /bin/sh;
shellScript = "target_name=$TARGET_NAME\ncp -r \"$TARGET_BUILD_DIR/$TARGET_NAME.app\" \"$TARGET_BUILD_DIR/${target_name}Plugin.xcplugin/\"";
};
D0C0DBA71921BC2900D46E04 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pre-build.sh\"";
};
D947634BDD8049989B0E2DE9 /* Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down
5 changes: 5 additions & 0 deletions CocoaControls/CocoaControls/RSCCAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,11 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification

#pragma mark - ITPullToRefreshScrollViewDelegate

- (void)pullToRefreshView:(ITPullToRefreshScrollView *)scrollView didReachRefreshingEdge:(ITPullToRefreshEdge)edge
{
NSLog(@"%d", (int)edge);
}

- (void)pullToRefreshView:(ITPullToRefreshScrollView *)scrollView
didStartRefreshingEdge:(ITPullToRefreshEdge)edge
{
Expand Down
106 changes: 106 additions & 0 deletions CocoaControls/ITPullToRefreshScrollView/ITPullToRefreshEdgeView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
//
// ITPullToRefreshEdgeView.h
// ITPullToRefreshScrollView
//
// Created by Ilija Tovilo on 9/25/13.
// Copyright (c) 2013 Ilija Tovilo. All rights reserved.
//

#import <Cocoa/Cocoa.h>
#import "ITPullToRefreshScrollView.h"

/**
* This view is used by the `ITPullToRefreshScrollView` to display the edges.
* You can extend from this class to create custom edges.
*/
@interface ITPullToRefreshEdgeView : NSView

/**
* Use this method to initialise an edge view
*
* @param edge - The edge which will the edge view be used for
*
* @return A new instance of `ITPullToRefreshEdgeView`
*/
- (instancetype)initWithEdge:(ITPullToRefreshEdge)edge;



// --------------------------
// ------------------- Events
// --------------------------

/**
* This method is called when the edge is triggered
*
* @param scrollView - The sender scroll view
*/
- (void)pullToRefreshScrollViewDidTriggerRefresh:(ITPullToRefreshScrollView *)scrollView;

/**
* This method is called when the edge is untriggered
*
* @param scrollView - The sender scroll view
*/
- (void)pullToRefreshScrollViewDidUntriggerRefresh:(ITPullToRefreshScrollView *)scrollView;

/**
* This method is called when the edge starts refreshing
*
* @param scrollView - The sender scroll view
*/
- (void)pullToRefreshScrollViewDidStartRefreshing:(ITPullToRefreshScrollView *)scrollView;

/**
* This method is called when the edge stops refreshing
*
* @param scrollView - The sender scroll view
*/
- (void)pullToRefreshScrollViewDidStopRefreshing:(ITPullToRefreshScrollView *)scrollView;

/**
* This is the final method called when the scroll view stopped animating
*
* @param scrollView - The sender scroll view
*/
- (void)pullToRefreshScrollViewDidStopAnimating:(ITPullToRefreshScrollView *)scrollView;

/**
* This method is called when part of the edge view becomes visible
*
* @param scrollView - The sender scroll view
* @param progress - The amount of the edge view that is visible (from 0.0 to 1.0)
*/
- (void)pullToRefreshScrollView:(ITPullToRefreshScrollView *)scrollView didScrollWithProgress:(CGFloat)progress;



// --------------------------
// ------------ Customisation
// --------------------------

/**
* Override this to remove the progress indicator and create other components
*/
- (void)installComponents;

/**
* The height of the edge view.
* Override this method to achieve a custom edge view height.
*
* @return The height of the edge view
*/
- (CGFloat)edgeViewHeight;

/**
* Override this method to draw a custom background.
* You can also just override `drawRect:` and to all the drawing on your own.
*
* @param The rect which should be drawn on
*/
- (void)drawBackgroundInRect:(NSRect)dirtyRect;


@property ITPullToRefreshEdge edgeViewEdge;

@end
226 changes: 226 additions & 0 deletions CocoaControls/ITPullToRefreshScrollView/ITPullToRefreshEdgeView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
//
// ITPullToRefreshEdgeView.m
// ITPullToRefreshScrollView
//
// Created by Ilija Tovilo on 9/25/13.
// Copyright (c) 2013 Ilija Tovilo. All rights reserved.
//

#import "ITPullToRefreshEdgeView.h"
#import <QuartzCore/QuartzCore.h>
#import "ITProgressIndicator.h"
#import "NSBKeyframeAnimation.h"

#define kDefaultEdgeViewHeight 30
#define kSpinnerSize 30

#define kMinSpinAnimationDuration 2.0
#define kMaxSpinAnimationDuration 8.0
#define kSpringRange 0.4

@interface ITPullToRefreshEdgeView () {
CGFloat _cachedProgress;
}
@property (strong) ITProgressIndicator *progressIndicator;
@end

@implementation ITPullToRefreshEdgeView


#pragma mark - Init

- (instancetype)initWithEdge:(ITPullToRefreshEdge)edge {
if (self = [super init]) {
_edgeViewEdge = edge;
[self installComponents];
}

return self;
}

- (void)installComponents {
self.progressIndicator = [[ITProgressIndicator alloc] initWithFrame:NSMakeRect(0, 0, kSpinnerSize, kSpinnerSize)];

[self.progressIndicator setWantsLayer:YES];
self.progressIndicator.animates = NO;
self.progressIndicator.hideWhenStopped = NO;
self.progressIndicator.isIndeterminate = NO;
self.progressIndicator.progress = 0.0;
self.progressIndicator.numberOfLines = 12;
self.progressIndicator.widthOfLine = 2.0;
self.progressIndicator.innerMargin = 5;
self.progressIndicator.color = [NSColor colorWithDeviceWhite:0.4 alpha:1.0];
self.progressIndicator.layer.contentsGravity = kCAGravityCenter;
[self.progressIndicator.layer setAnchorPoint:CGPointMake(0.5, 0.5)];

[self addSubview:self.progressIndicator];


// Install Layout Constraints
{
[self.progressIndicator setTranslatesAutoresizingMaskIntoConstraints:NO];

[self.progressIndicator addConstraint:[NSLayoutConstraint constraintWithItem:self.progressIndicator
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1
constant:kSpinnerSize]];
[self.progressIndicator addConstraint:[NSLayoutConstraint constraintWithItem:self.progressIndicator
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1
constant:kSpinnerSize]];

[self addConstraint:[NSLayoutConstraint constraintWithItem:self.progressIndicator
attribute:NSLayoutAttributeCenterY
relatedBy:0
toItem:self
attribute:NSLayoutAttributeCenterY
multiplier:1
constant:0]];
[self addConstraint:[NSLayoutConstraint constraintWithItem:self.progressIndicator
attribute:NSLayoutAttributeCenterX
relatedBy:0
toItem:self
attribute:NSLayoutAttributeCenterX
multiplier:1
constant:0]];
}
}


#pragma mark - Constraints

- (void)viewDidMoveToSuperview {
[self setUpConstraints];
}

- (void)setUpConstraints {
[self setTranslatesAutoresizingMaskIntoConstraints:NO];

[self addConstraint:[NSLayoutConstraint constraintWithItem:self
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1
constant:[self edgeViewHeight]]];

[self.superview addConstraint:[NSLayoutConstraint constraintWithItem:self
attribute:NSLayoutAttributeLeft
relatedBy:NSLayoutRelationEqual
toItem:self.superview
attribute:NSLayoutAttributeLeft
multiplier:1.0
constant:0.0]];
[self.superview addConstraint:[NSLayoutConstraint constraintWithItem:self
attribute:NSLayoutAttributeRight
relatedBy:NSLayoutRelationEqual
toItem:self.superview
attribute:NSLayoutAttributeRight
multiplier:1.0
constant:0.0]];

if (self.edgeViewEdge & ITPullToRefreshEdgeTop)
{
[self.superview addConstraint:[NSLayoutConstraint constraintWithItem:self
attribute:NSLayoutAttributeBottom
relatedBy:NSLayoutRelationEqual
toItem:[(NSClipView *)self.superview documentView]
attribute:NSLayoutAttributeTop
multiplier:1.0
constant:0.0]];
}
else if (self.edgeViewEdge & ITPullToRefreshEdgeBottom)
{
[self.superview addConstraint:[NSLayoutConstraint constraintWithItem:self
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:[(NSClipView *)self.superview documentView]
attribute:NSLayoutAttributeBottom
multiplier:1.0
constant:0.0]];
}
}


#pragma mark - Customisation Methods

- (CGFloat)edgeViewHeight {
return kDefaultEdgeViewHeight;
}

- (void)drawRect:(NSRect)dirtyRect {
[self drawBackgroundInRect:dirtyRect];
}

- (void)drawBackgroundInRect:(NSRect)dirtyRect {
[[NSColor colorWithDeviceWhite:0.96 alpha:1.0] set];
NSRectFill(dirtyRect);
}

- (void)pullToRefreshScrollView:(ITPullToRefreshScrollView *)scrollView didScrollWithProgress:(CGFloat)progress {
_cachedProgress = progress;

if (progress < 1.0) {
self.progressIndicator.isIndeterminate = NO;
self.progressIndicator.progress = progress;
}
}

- (void)pullToRefreshScrollViewDidTriggerRefresh:(ITPullToRefreshScrollView *)scrollView {
self.progressIndicator.isIndeterminate = NO;
self.progressIndicator.progress = 1.0;
}

- (void)pullToRefreshScrollViewDidUntriggerRefresh:(ITPullToRefreshScrollView *)scrollView {

}

- (void)pullToRefreshScrollViewDidStartRefreshing:(ITPullToRefreshScrollView *)scrollView {
CGFloat tension = (_cachedProgress - 1.0 <= kSpringRange)?_cachedProgress - 1:kSpringRange;
CGFloat duration = kMaxSpinAnimationDuration - ((kMaxSpinAnimationDuration - kMinSpinAnimationDuration) * (1.0 / kSpringRange * tension));

[self.progressIndicator.layer addAnimation:[self rotationAnimationWithDuration:duration] forKey:@"rotation"];
self.progressIndicator.isIndeterminate = YES;
self.progressIndicator.animates = YES;
}

- (void)pullToRefreshScrollViewDidStopRefreshing:(ITPullToRefreshScrollView *)scrollView {
self.progressIndicator.animates = NO;
self.progressIndicator.isIndeterminate = NO;

[self.progressIndicator.layer addAnimation:[self shrinkAnimation] forKey:@"shrink"];
}

- (void)pullToRefreshScrollViewDidStopAnimating:(ITPullToRefreshScrollView *)scrollView {
[self.progressIndicator.layer removeAnimationForKey:@"rotation"];
}

- (CAAnimation *)shrinkAnimation {
NSBKeyframeAnimation *animation = [NSBKeyframeAnimation animationWithKeyPath:@"transform.scale"
duration:0.3
startValue:1
endValue:0.0
function:NSBKeyframeAnimationFunctionEaseOutCubic];

return animation;
}

- (CAAnimation *)rotationAnimationWithDuration:(CGFloat)duration {
NSBKeyframeAnimation *animation = [NSBKeyframeAnimation animationWithKeyPath:@"transform"
duration:duration
startValue:0
endValue:-2 * M_PI
function:NSBKeyframeAnimationFunctionEaseOutCubic];

[animation setValueFunction:[CAValueFunction functionWithName: kCAValueFunctionRotateZ]];

return animation;
}

@end
Loading

0 comments on commit 6531758

Please sign in to comment.