From 633d23a78c21e0616b76ab9b7f840d81317538e5 Mon Sep 17 00:00:00 2001 From: Chris Scoville Date: Sun, 21 Feb 2016 15:15:44 -0800 Subject: [PATCH] Adding the option of using completion blocks for the appear and disappear animations. --- .../ZCAnimatedLabel/ZCAnimatedLabel.h | 4 ++++ .../ZCAnimatedLabel/ZCAnimatedLabel.m | 22 +++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/ZCAnimatedLabel/ZCAnimatedLabel/ZCAnimatedLabel.h b/ZCAnimatedLabel/ZCAnimatedLabel/ZCAnimatedLabel.h index 7984e17..1e5d02d 100644 --- a/ZCAnimatedLabel/ZCAnimatedLabel/ZCAnimatedLabel.h +++ b/ZCAnimatedLabel/ZCAnimatedLabel/ZCAnimatedLabel.h @@ -93,8 +93,12 @@ typedef NS_ENUM(NSInteger, ZCAnimatedLabelAppearDirection) - (void) startAppearAnimation; +- (void) startAppearAnimationWithCompletion:(void (^)(void))completion; + - (void) startDisappearAnimation; +- (void) startDisappearAnimationWithCompletion:(void (^)(void))completion; + - (void) stopAnimation; /** diff --git a/ZCAnimatedLabel/ZCAnimatedLabel/ZCAnimatedLabel.m b/ZCAnimatedLabel/ZCAnimatedLabel/ZCAnimatedLabel.m index a2dc1c4..599a383 100644 --- a/ZCAnimatedLabel/ZCAnimatedLabel/ZCAnimatedLabel.m +++ b/ZCAnimatedLabel/ZCAnimatedLabel/ZCAnimatedLabel.m @@ -19,6 +19,8 @@ @interface ZCAnimatedLabel () @property (nonatomic, assign) BOOL animatingAppear; //we are during appear stage or not @property (nonatomic, strong) ZCCoreTextLayout *layoutTool; @property (nonatomic, assign) NSTimeInterval animationStarTime; +@property (nonatomic, copy) void (^appearAnimationCompleted)(void); +@property (nonatomic, copy) void (^disappearAnimationCompleted)(void); @end @@ -84,6 +86,11 @@ - (void) timerTick: (id) sender if (self.animationTime > self.animationDurationTotal) { self.displayLink.paused = YES; self.useDefaultDrawing = YES; + if (self.animatingAppear && self.appearAnimationCompleted != nil) { + self.appearAnimationCompleted(); + } else if (!self.animatingAppear && self.disappearAnimationCompleted != nil) { + self.disappearAnimationCompleted(); + } } else { //update text attributeds array @@ -262,9 +269,9 @@ - (void) setUseDefaultDrawing:(BOOL)useDefaultDrawing [self setNeedsDisplay]; } - -- (void) startAppearAnimation +- (void) startAppearAnimationWithCompletion:(void (^)(void))completion { + self.appearAnimationCompleted = completion; self.animatingAppear = YES; self.animationTime = 0; self.useDefaultDrawing = NO; @@ -273,8 +280,19 @@ - (void) startAppearAnimation [self setNeedsDisplay]; } +- (void) startAppearAnimation +{ + [self startAppearAnimationWithCompletion:nil]; +} + - (void) startDisappearAnimation { + [self startDisppearAnimationWithCompletion:nil]; +} + +- (void) startDisppearAnimationWithCompletion:(void (^)(void))completion +{ + self.disappearAnimationCompleted = completion; self.animatingAppear = NO; self.animationTime = 0; self.useDefaultDrawing = NO;