Skip to content

Commit

Permalink
updated README
Browse files Browse the repository at this point in the history
added method for opening and closing
removed delegate and added completion block
0.2 podspec tag
  • Loading branch information
Dzamir committed Aug 11, 2015
1 parent b687660 commit 958bda0
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 16 deletions.
Binary file added 4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion DZAObliqueFillAnimatorView.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "DZAObliqueFillAnimatorView"
s.version = "0.1.0"
s.version = "0.2.0"
s.summary = "Custom view with an oblique transparent cut on the top"
s.description = <<-DESC
A custom view that has an oblique transparent cut on the top and it can be filled with an animated circle
Expand Down
16 changes: 14 additions & 2 deletions Example/DZAObliqueFillAnimatorView/DZAViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

@interface DZAViewController ()
@property (weak, nonatomic) IBOutlet DZAObliqueFillAnimatorView *obliqueView;
@property (readwrite, nonatomic) BOOL isOpened;


@end

Expand All @@ -19,7 +21,7 @@ @implementation DZAViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_isOpened = NO;
}

- (void)didReceiveMemoryWarning
Expand All @@ -30,7 +32,17 @@ - (void)didReceiveMemoryWarning

- (IBAction)animateTouchUpInside:(id)sender
{
[_obliqueView animateWithDuration:0.5];
if (_isOpened)
{
[_obliqueView animateOpeningWithDuration:0.5 completion:^{
_isOpened = !_isOpened;
}];
} else
{
[_obliqueView animateClosingWithDuration:0.5 completion:^{
_isOpened = !_isOpened;
}];
}
}

- (IBAction)sliderValueChanged:(UISlider *)sender
Expand Down
9 changes: 2 additions & 7 deletions Pod/Classes/DZAObliqueFillAnimatorView.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@

@class DZAObliqueFillAnimatorView;

@protocol DZAObliqueFillAnimatorViewDelegate <NSObject>

-(void) obliqueFillAnimatorViewDidCompleteAnimation:(DZAObliqueFillAnimatorView *) obliqueFillAnimatorView;

@end

IB_DESIGNABLE
@interface DZAObliqueFillAnimatorView : UIView
Expand All @@ -28,8 +23,8 @@ IB_DESIGNABLE

@property (readonly, nonatomic) BOOL isAnimating;

@property (nonatomic, assign) id<DZAObliqueFillAnimatorViewDelegate> delegate;
-(void) animateOpeningWithDuration:(double) duration completion:(void(^)(void)) completion;

-(void) animateWithDuration:(double) duration;
-(void) animateClosingWithDuration:(double) duration completion:(void(^)(void)) completion;

@end
32 changes: 27 additions & 5 deletions Pod/Classes/DZAObliqueFillAnimatorView.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ @interface DZAObliqueFillAnimatorView()
double _frameTimestamp;
double _initialAnimationTimestamp;
double _animationDuration;
double _animationInitialFillPercentage;
BOOL _isOpening;
CADisplayLink *_displayLink;
}

@property (nonatomic, copy) void (^animationCompletion)(void);

@end

@implementation DZAObliqueFillAnimatorView
Expand All @@ -25,6 +29,7 @@ - (instancetype) initWithFrame:(CGRect)aRect
if (self = [super initWithFrame:aRect])
{
_isAnimating = NO;
_isOpening = NO;
_frameTimestamp = -1;
_initialAnimationTimestamp = -1;
_startsFromLeft = YES;
Expand Down Expand Up @@ -83,39 +88,56 @@ - (void)drawRect:(CGRect)rect {
}

// starts the fill animation
-(void) animateWithDuration:(double) duration
-(void) animateOpeningWithDuration:(double) duration completion:(void(^)(void)) completion isOpening:(BOOL) isOpening;
{
if (!_isAnimating)
{
self.animationCompletion = completion;
_isAnimating = YES;
_isOpening = isOpening;
_frameTimestamp = -1;
_initialAnimationTimestamp = -1;
_animationInitialFillPercentage = (_isOpening? _fillPercentage: 1.0 - _fillPercentage);
_animationDuration = duration;
_displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(updateAnimation:)];
[_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
}
}

-(void) animateOpeningWithDuration:(double) duration completion:(void(^)(void)) completion;
{
[self animateOpeningWithDuration:duration completion:completion isOpening:YES];
}

-(void) animateClosingWithDuration:(double) duration completion:(void(^)(void)) completion;
{
[self animateOpeningWithDuration:duration completion:completion isOpening:NO];
}

- (void) updateAnimation:(CADisplayLink *) displayLink
{
double currentTime = [displayLink timestamp];
if (_frameTimestamp < 0)
{
_frameTimestamp = 0;
_initialAnimationTimestamp = currentTime;
}
_frameTimestamp = currentTime;
double passedTimeFromStart = _frameTimestamp - _initialAnimationTimestamp;
double passedTimeFromStart = _frameTimestamp - _initialAnimationTimestamp + (_animationInitialFillPercentage * _animationDuration);
_fillPercentage = passedTimeFromStart / _animationDuration;
if (!_isOpening)
{
_fillPercentage = 1.0 - _fillPercentage;
}
[self setNeedsDisplay];

if (passedTimeFromStart > _animationDuration)
{
[_displayLink removeFromRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
_isAnimating = NO;
if (self.delegate)
if (self.animationCompletion)
{
[self.delegate obliqueFillAnimatorViewDidCompleteAnimation:self];
self.animationCompletion();
self.animationCompletion = nil;
}
}
}
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,21 @@ Screenshots:

To run the example project, clone the repo, and run `pod install` from the Example directory first.

## Requirements
The view supports Interface Builder integration: you just need to drag a UIView and change the class to DZAObliqueFillAnimatorView

![](https://raw.githubusercontent.com/Dzamir/DZAObliqueFillAnimatorView/master/4.png)

From the IB you can change the parameters and colors to match your app style.

From the code you call

[_obliqueView animateOpeningWithDuration:0.5 completion:nil];

or

[_obliqueView animateClosingWithDuration:0.5 completion:nil];

to animate the transition.

## Installation

Expand Down

0 comments on commit 958bda0

Please sign in to comment.