-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pre build script to copy modified ITPullToRefreshScrollView files…
… to pods
- Loading branch information
1 parent
d73d03c
commit 6531758
Showing
7 changed files
with
777 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
CocoaControls/ITPullToRefreshScrollView/ITPullToRefreshEdgeView.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
226
CocoaControls/ITPullToRefreshScrollView/ITPullToRefreshEdgeView.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.